您的位置:首页 > 其它

使用strstr()函数在一个字符串中查找另一个字符串

2015-10-24 00:00 363 查看
#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;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: