strstr()函数是把主串中子串及子串以后的字符返回
eg:主串:“12345678”,子串:”234“,那么函数的返回值就是”2345678“
#include <stdio.h>
#include<iostream>
#include<string.h>
using namespace std;
const char *my_strstr(const char *str, const char *sub_str)
{
int i;
for(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;
}
int main()
{
char *s = "1233345hello";
char sub[4];
printf("please input num:\n");
//字符串的输入输出 char与string
cin>>sub;
//cin.getline(sub,4);
printf("%s\n", my_strstr(s, sub));
return 0;
}