#include <stdio.h>
#include <string.h>
int main(void){
char *loc, buf1[80], buf2[80];
//输入字符串
printf("Enter the string to be searched: ");
gets(buf1);
printf("Enter the target string: ");
gets(buf2);
//执行查找
loc = strstr(buf1, buf2);
if(loc == NULL){
printf("No match was found.\n");
} else {
printf("%s was found at positioin %d.\n", buf2, loc-buf1);
}
return 0;
}
转载于:https://my.oschina.net/u/241930/blog/521453