#define _CRT_SECURE_NO_WARNINGS 1
#include<stdio.h>
#include<stdlib.h>
#include<assert.h>
#include<string.h>
char *mystrstr(const char *dst_str,const char *src_str)
{
const char *dst_start = dst_str;
const char *dst_end = dst_str + strlen(dst_str) - strlen(src_str);
const char *src_start = src_str;
char *pos = dst_start;
assert(dst_str);
assert(src_str);
if (strlen(dst_str) < strlen(src_str))
{
return NULL;
}
while (dst_start <= dst_end)
{
pos = dst_start;
while ((*dst_start == *src_start) && (*src_start != '\0'))
{
dst_start++,src_start++;
}
if (*src_start == '\0')
{
return pos;
}
dst_start = pos + 1;
src_start = src_str;
}
return NULL;
}
int main()
{
char msg[] = "where are you from";
char str[] = "are";
printf("before : %s\n",msg);
printf("find after : %s\n",mystrstr(msg,str));
system("pause");
return 0;
}