#include <stdio.h>
#include <string.h>
char *my_strstr(char *str,char *substr)
{
int len1 = strlen(str);
int len2 = strlen(substr);
if(!len2)
return (char *)str;
while(len1 >= len2)
{
len1--;
if(!memcmp(str,substr,len2))
return (char *)str;
str++;
}
return NULL;
}
int main(void)
{
char *str = "Hello world";
char *substr = "llo";
printf("%s\n",my_strstr(str,substr));
printf("%s\n",strstr(str,substr));
return 0;
}
strstr函数的简单实现
最新推荐文章于 2023-12-05 17:54:47 发布