#include <stdio.h>
const 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;
}
int main()
{
char s[50];
char sub[40];
scanf("%s %s", s,sub);
if( my_strstr(s, sub)!=NULL)
printf("找到字符串:%s\n", my_strstr(s, sub));
else
printf("未找到该字符串!");
return 0;
}
const 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;
}
int main()
{
char s[50];
char sub[40];
scanf("%s %s", s,sub);
if( my_strstr(s, sub)!=NULL)
printf("找到字符串:%s\n", my_strstr(s, sub));
else
printf("未找到该字符串!");
return 0;
}