#include <stdio.h>
#include <assert.h>
char *my_strstr(const char *dest, const char *src)
{
assert(dest != NULL && src != NULL);
if (*src == '\0')
return (char *)src;
const char *p1 = dest;
const char *p2 = src;
const char *cur = p1;
while (*cur)
{
p1 = cur;
p2 = (char *)src;
while ((*p1 != '\0') && (*p2 != '\0') && (*p1 == *p2))
{
p1++;
p2++;
}
if (*p2 == '\0')
return (char *)cur;
cur++;
}
return NULL;
}
int main()
{
char *name1 = "abcdef";
char *name2 = "cd";
char *ret = my_strstr(name1, name2);
if (ret == NULL)
{
printf("查无此串\n");
}
else
{
printf("%s\n", ret);
}
return 0;
}