自己整理的关于C的一些字符串处理函数
鉴于在用C语言写一些字符串处理的程序时种种的不便,本人坚信"磨刀不误砍柴功"这个信条,于是在专门
进行了一次磨对C语言的磨刀,写了一些字符串的处理函数, 方便网友使用, 大家有好的解决方法也请告知一下.
我估计有一些C的库中肯定有比我这更好的函数, 但是本人没有找到, 望"行家"告知.
#include <string.h>
/********************************************************
返回字符ch在head字符串中首次出现的位置
********************************************************/
int indexString(char* head, char ch)
{
int i=0;
int flag=0;
while(head[i]!=0)
{
if(head[i] == ch)
{
flag=1;
break;
}
i++;
}
if(flag)
return i;
else
return -1;
}
/********************************************************
求子字符串的函数:取字符串head中从start位置到end
位置处的字符串,如head="hello world xphag",
subString(head, 0, strlen(head)-1)的结果为"hello world xphag"
subString(head, 0, 0)的结果为"h"
********************************************************/
char* subString(char* head, int start, int end)//取字符串的start位置到end位置的子字符串(含start),失败返回NULL
{
int i=0, j=0;
i=strlen(head);
if(start>=i || end>= i || start> end)
return NULL;
char* p=(char* )malloc(sizeof(char)* (end-start+2));
for(i=start; i<=end; i++ )
相关文档:
C/C++ optimizing compilers are great--but there *are* a few techniques for hand-tuning your code to run as efficiently as possible on the AMD Athlon64 and Opteron processors, especially when developing DLLs, device drivers, or other performance-bound pieces of code.
Alan Zeichick
Share | ......
利用
下载的这段代码,成功实现了守护进程,原来守护进程是很简单的事情。
在main函数中执行
init_daemon();//初始化为Daemon
就可以把进程变成守护进程
#include
#include
#include
#include
#include
void
init_daemon(void
)
{
int
pid;
int
i;
if
(pid=fork()) ......
// & 与,将指定位置设置为0 | 或,将指定位置设置为1
//注: 只针对纯字母的情况
#include <stdio.h>
#include <string>
int main()
{
char str[6] = "xxing";
std::string str1 = "INGXX";
for(int i = 0; i < 5; i++)
{
str[i] &= 0xdf; ......
c指针的运算有时候还是很迷惑人的。
例如:
struct student {
int num;
int score;
int length;
};
struct student *pt;
pt = (struct student *) malloc(sizeof(struct student));
pt->num = 1;
pt->score = 90;
pt->length = 3 * sizeof(int);
printf("pt length:%d\n", *pt);
pt = (int ......
時間不等人,在我還未老去之前,想把丟掉的C程式重新再揀起來。
入門,建議(我也是新手)不要看譚大爺的書,對于20世紀學習C語言,c Primer Plus 5th我認為是一個好的選擇。
我的第一& ......