#include <stdio.h>
#include <string.h>
#include <assert.h>
//strstr 查看str1中是否有str2,有则返回str1z中
//的相同的第一字符的起始地址,没有则NULL
char* my_strstr(const char* str1, const char* str2)
{
assert(str1 && str2);
const char* s1 = NULL;
const char* s2 = NULL;
const char* cp = str1;
if (*str2=='\0')
{
return (char*)str1;
}
while (*cp)
{
s1 = cp;
s2 = str2;
while(*s1&&*s2&&(*s1==*s2))
{
s1++;
s2++;
}
if (*s2=='\0')
{
return (char*)cp;
}
cp++;
}
return NULL;
}
int main()
{
char arr1[] = "abbbcdef";
char arr2[] = "bbc";
// char* ret = strstr(arr1, arr2);
char* ret = my_strstr(arr1, arr2);
if (ret == NULL)
{
printf("无");
}
else
{
printf("%s", ret);
}
return 0;
}