1.strcpy #include<stdio.h> #include<assert.h> char *strcpy(char *str1,char const*str2) { char *s=str1; assert(str2!=NULL); assert(str1!=NULL); while((*str1++=*str2++)!=‘\0‘) { ; } return s; } int main() { char s1[]="0"; char s2[]="abcdef"; printf("%s\n",strcpy(s1,s2)); system("pause"); return 0; } 2.strcmp #include<stdio.h> #include<assert.h> int strcmp(char *str1,char *str2) { assert(str1!=NULL); assert(str2!=NULL); while(*str1++==*str2++) { ; if(str1==‘\0‘) return 0; } if(*str1>*str2) return 1; else return -1; } int main() { char s1[]="abbb"; char s2[]="abbvvcg"; printf("%d\n", strcmp(s1,s2)); system("pause"); return 0; } 3.strcat #include<stdio.h> #include<assert.h> #include<string.h> char *strcat(char *s1,char const*s2) { int len=strlen(s1); assert(s1!=NULL); assert(s2!=NULL); while(*s2!=‘\0‘) { *(s1+len-1)=*s2; *s2++; } s1=‘\0‘; return s1; } int main() { char s1[]="hello"; char s2[]="word!"; printf("%s",strcat(s1,s2)); system("pause"); return 0; }
原文:http://760470897.blog.51cto.com/10696844/1707255