代码区
#include <stdio.h>
#include <string.h>
int BF(const char *s, const char *sub, int pos)
{
int i = pos;
int j = 0;
int lens = strlen(s);
int lensub = strlen(sub);
while (i<lens && j<lensub)
{
if (s[i] == sub[j])
{
i++;
j++;
}
else
{
i = i - j + 1;
j = 0;
}
}
if (j >= lensub)
{
return i - j+1;
}
else
{
return -1;
}
}
int main()
{
char s[80],sub[80];
int n;
printf("输入主串\n");
gets(s);
printf("输入模式串\n");
gets(sub);
printf("输入查找位置\n");
scanf("%d",&n);
if(BF(s, sub, n-1))
printf("%d\n",BF(s, sub, n-1) );
else
printf("not match\n");
return 0;
}