、string.h 中的常见函数 1、函数名称: strcpy 函数原型: char* strcpy(char* str1,char* str2); 函数功能: 把 str2 指向的字符串拷贝到 str1 中去 函数返回: 返回 str1,即指向 str1 的指针 参数说明: 所属文件: #include #include int main() { char string[10]; char *str1="abcdefghi"; strcpy(string,str1); printf("the string is:%s\n",string); return 0; 2、函数名称: strcat 函数原型: char* strcat(char * str1,char * str2); 函数功能: 把字符串 str2 接到 str1 后面,str1 最后的'\0'被取消 函数返回: str1 参数说明: 所属文件: #include #include int main() { char buffer[80]; strcpy(buffer,"Hello "); strcat(buffer,"world"); printf("%s\n",buffer); return 0; } 3、函数名称: strcmp 函数原型: int strcmp(char * str1,char * str2); 函数功能: 比较两个字符串 str1,str2. 函数返回: str1str2,返回正数. 参数说明: 所属文件: #include #include int main() { char *buf1="aaa", *buf2="bbb", *buf3="ccc"; int ptr; ptr=strcmp(buf2, buf1); if(ptr>0) printf("buffer 2 is greater than buffer 1\n"); else printf("buffer 2 is less than buffer 1\n"); ptr=strcmp(buf2, buf3); if(ptr>0) printf("buffer 2 is greater than buffer 3\n"); else printf("buffer 2 is less than buffer 3\n"); return 0; 4、函数名称: strchr 函数原型: char* strchr(char* str,char ch); 函数功能: 找出 str 指向的字符串中第一次出现字符 ch 的位置 函数返回: 返回指向该位置的指针,如找不到,则返回空指针 参数说明: str-待搜索的字符串,ch-查找的字符 所属文件: #include #include int main() { char string[15]; char *ptr, c='r'; strcpy(string, "This is a string"); ptr=strchr(string, c); if (ptr) printf("The character %c is at position: %d\n",c,ptr-string); else printf("The character was not found\n"); return 0; } 5、...