请高手帮我看看这道字符串a和b比较的问题!!!

来源:百度知道 编辑:UC知道 时间:2024/06/22 00:14:05
输入两个字符串a和b,判断字符串b是否是字符串a的字串.是则输出b串在a串中的开始位置;否则输出-1.例如串a="ABCDE",若串b="CD",则输出3;若串b="CE",则输出-1.

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
char a[100];
char b[100];
char *p;
scanf("%s%s",a,b);
p=strstr(a,b);
if(p)
printf("%d",p-a+1);
else
printf("-1");
system("pause");
return 0;
}

算法问题!!一位位比较就行了

用strstr函数啊