Linux字符串操作大全 (1)strcat(连接两字符串) 相关函数 bcopy,memccpy,memcpy,strcpy,strncpy 头文件 #include 函数定义 char *strcat (char *dest,const char *src); 函数说明 strcat()会将参数src 字符串拷贝到参数dest 所指的字符串尾
第一个参数dest 要有足够的空间来容纳要拷贝的字符串
返回值 返回参数dest 的字符串起始地址 范例 #include #include main() { char a[30]="string(1)"; char b[]="string(2)"; printf("before strcat() : %s\n",a); printf("after strcat() : %s\n",strcat(a,b)); } 执行 before strcat () : string(1) after strcat () : string(1)string(2) (2)strchr(查找字符串中第一个出现的指定字符) 相关函数 index,memchr,rinex,strbrk,strsep,strspn,strstr,strtok 头文件 #include 函数定义 char * strchr (const char *s,int c); 函数说明 strchr()用来找出参数s 字符串中第一个出现的参数c 地址,然后将该字符出现的地址返回
返回值 如果找到指定的字符则返回该字符所在地址,否则返回 0
范例 #include #include main() { char *s="0123456789012345678901234567890"; char *p; p=strchr(s,'5'); if (p) { p