zj@zj:~/C_parm/string/own_str/strstr$ gcc -o strcasestr strcasestr.c
cat strcasestr.c /*
*The strstr() function finds the first occurrence of the substring
*needle in the string haystack. The terminating '\0' characters
*are not compared.
*strstr.c
*/
char* my_strcasestr(constchar* s1,constchar* s2); int my_strncmp(constchar* s1,constchar* s2,int len);
int main() { char* str1 ="CDEcd"; char* str2 ="cde"; printf("the first ocu %s of %s is:\n%s\n",str2,str1,my_strcasestr(str1,str2)); exit(EXIT_SUCCESS); }
char* my_strcasestr(constchar* s1,constchar* s2) { int len2 =strlen(s2);/* 获得待查找串的长度*/ int tries;/* maximum number of comparisons */ int nomatch = 1;/* set to 0 if match is found */
}while(ch1&&ch2&&(ch1 == ch2)&&len--); printf("ch1-ch2=%d\n",ch1-ch2); return(ch1 - ch2); }
zj@zj:~/C_parm/string/own_str/strstr$./strcasestr
ch1-ch2=0
the first ocu cde of CDEcd is:
CDEcd