1 int myStrlen(const char *src) 2 { 3 int len = 0; 4 while(*src++) 5 { 6 len++; 7 } 8 return len; 9 }
1 char* myStrcpy(char* dest,const char* src) 2 { 3 char *d = dest; 4 while(*dest++ == *src++); 5 return d; 6 }
1 char* myStrcat(char* dest,const char* src) 2 { 3 char *d = dest; 4 while(*dest) dest++; 5 while(*dest++ = *src++); 6 return d; 7 }
1 int myStrcmp(const char* s1,const char* s2) 2 { 3 #if 0 4 for(;(*s1&&*s2)&&(*s1++ == *s2++);); 5 return *s1-*s2; 6 #endif 7 8 #if 0 9 for(;(*s1&&*s2)&&(*s1++ == *s2++);); 10 return *s1-*s2; 11 12 #endif 13 14 #if 0 15 for(; *s1 && *s2 ;s1++,s2++) 16 { 17 if(*s1 != *s2) 18 break; 19 } 20 return *s1 - *s2; 21 #endif 22 23 #if 0 24 for(;;str1++,str2++) 25 { 26 if(*str1 != *str2) 27 return *str1-*str2; 28 if(*str1 == 0)//两个字符串同时到结尾 29 return 0; 30 } 31 #endif 32 }
1 char * myStrstr(char *str, char *subStr)//调用库函数实现 2 { 3 if(*subStr == '