字符串函数strstr(char *s1,char *s2)是返回字符串s1中首次出现s2的地址
函数实现:
- char *my_strstr( char *s1, char *s2)
- {
- if(*s2 == '\0')
- {
- return NULL;
- }
-
- char *a = s1;
- char *b = s1;
- char *c = s2;
-
- while(*a != '\0')
- {
- if(*b == *c)
- {
- b++;
- c++;
- if(*c == '\0')
- {
- return a;
- }
- }
- else
- {
- a++;
- b = a;
- c = s2;
- }
- }
- return NULL;
- }