#include <stdio.h>
#include <assert.h>
#include <string.h>
//在字符串haystack中查找第一次出现字符串needle的位置
char *my_strstr(const char *haystack, const char *needle)
{
assert(haystack != NULL && needle != NULL);
char *a = (char *)haystack;
char *b = (char *)needle;
while(*a != NULL)
{
if(0 == strncmp(a, b, strlen(b)))
{
return a;
}
a++;
}
return NULL;
}
int main ()
{
char str1[] = {"asabcdfjj"};
char str2[] = {"abc"};
printf("my strstr %s\n", my_strstr(str1, str2)); //abcdfjj
return 0;
}