#include<stdlib.h>
#include<stdio.h>
#include<assert.h>
char* myStrstr(char srce[],char check[]){
assert(NULL != srce && NULL != check);
char *sr,*ch,*ret;
sr=srce;
ch=check;
while(*sr != ‘\0‘)
{
while(*sr && *sr != *ch) sr++;
ret=sr;
while(*sr && *ch && *sr == *ch)
{
ch++;sr++;
}
if(*ch == ‘\0‘) return ret;
if(*sr == ‘\0‘) return NULL;
ch=check;
}
return NULL;
}
char* standardStrstr(const char *src,const char *dest){
assert(src!=NULL && dest!=NULL);
if(!*dest) return src;
while(*src){
int i=0;
for(;*(src+i)==*(dest+i);i++){
if(!*(dest+i+1)) return src;
}
src++;
}
return NULL;
}
int main(){
char sr[]={‘a‘,‘b‘,‘c‘,‘\0‘};
char ch[]={‘b‘,‘\0‘};
char *sr1="how are you baby";
char *ch1="";
char *ret= myStrstr(sr,ch);
char *ret1= standardStrstr(sr1,ch1);
if(NULL != ret){//如果打印null会返回段错误
printf("result is:%c\n",*ret);
printf("result1 is:%c\n",*ret1);
}
return -1;
}