#include <iostream>
using namespace std;
const char * myStrstr(const char * src, const char *sub_str)
{
for (int index = 0; src[index] != '\0'; index++)
{
int j = 0;
int temp = index;
if (src[index] == sub_str[j])
{
while (src[index++] == sub_str[j++])
{
if (sub_str[j] == '\0')
{
return &src[index - j];
}
}
index = temp;
}
}
return NULL;
}
int main()
{
char *strSrc = "123456789";
char *strSub = "34";
cout<<myStrstr(strSrc,strSub);
return 0;
}
strstr函数实现
最新推荐文章于 2021-11-17 17:04:43 发布