|
#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;
}
复制代码 |
|