strstr() 函数搜索一个字符串在另一个字符串中的第一次出现。该函数返回字符串的其余部分(从匹配点)。如果未找到所搜索的字符串,则返回 false。该函数是二进制安全的。
//数组
#include <stdio.h>
char *my_strstr(const char *str, const char *sub_str)
{
for(int i = 0; str[i] != ‘\0‘; i++)
{
int tem = i; //tem保留主串中的起始判断下标位置
int j = 0;
while(str[i++] == sub_str[j++])
{
if(sub_str[j] == ‘\0‘)
{
return &str[tem];
}
}
i = tem;
}
return NULL;
}本文出自 “无以伦比的暖阳” 博客,请务必保留此出处http://10797127.blog.51cto.com/10787127/1714868
原文:http://10797127.blog.51cto.com/10787127/1714868