看了glibc中的strstr函数的实现,感觉很是复杂,所以重写了小巧点的,希望大家笔试中能用得到哈:-D
char *strstr(char *s1, char *s2)
{
if (NULL == s1 || NULL == s2)
return NULL;
char *p1 = s1;
char *p2 = s2;
char *ret = NULL;
while (*p1)
{
if (*p1++ == *p2)
{
if (NULL == ret)
ret = p1 - 1;
if (*++p2)
continue;
else
return ret;
}
else
ret = NULL;
}
return NULL;
}
或许存在bug,欢迎指正,大家一起用哈。
char *strstr(char *s1, char *s2)
{
}
或许存在bug,欢迎指正,大家一起用哈。
<script type="text/javascript" id="wumiiRelatedItems"> </script>