库函数实现:strstr,子字符串查找,char *strstr(char *sSource,char *sTarget),在sSource中查找子串sTarget,能找到则返回sTarget子串,找不到返回NULL。
C语言代码如下:
char *strstr(char *sSource,char *sTarget)
{
char *p = sTarget;
while(*sSource && *sTarget){
if(*sSource == *sTarget){
sTarget++;
}
else{
sTarget=p;
}
sSource++;
}
if(*sTarget)
return NULL;
else
return p;
}