题目:编写函数char *search_substr(char *s, char *t),在字符串s中查找字符串t,返回子串t的首地址,若未找到,则返回NULL
#include <stdio.h>
char *search_substr(char *s, char *t);
int main()
{
char s[50], t[20], *p = NULL;
gets(s);
gets(t);
p = search_substr(s, t);
if(p){
printf("%s\n", p);
}else{
printf("Not in");
}
return 0;
}
char *search_substr(char *s, char *t){
char *p = s;
char *q = t;
int num = 0;
while(*p != '\0'){
if(*p == *q){
num++;
q++;
}else{
q = t;
}
p++;
if(*q == '\0'){
return p-num;
}
}
return NULL;
}