#include<stdio.h>
char* mystrstr(const char* str, const char* dst)
{
if ((str == NULL) && (dst == NULL))
{
return NULL;
}
char* s1 = (char*)str;
char* s2 = (char*)dst;
char* s3 = NULL;
if (*dst == '\0')
{
return NULL;
}
while (*s1)
{
s3 = s1;
s2 = dst;
while (*s1 && *s2 && (*s3 == *s2))
{
s3++;
s2++;
}
if (*s2 == '\0')
{
return s1;
}
s1++;
}
}
int main()
{
char* str = "abcccdef";
char* dst = "cde";
char* ret = mystrstr(str, dst);
printf("%s\n", ret);
system("pause");
return 0;
}
实现strstr
最新推荐文章于 2020-11-23 18:16:50 发布