串就是字符串,
我写的不太严谨,见谅
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<stdbool.h>
#define MaxSize 10
typedef struct {
char data[MaxSize];
int length;
}SqString;
int BF(SqString s, SqString t)
{
int i=0, j = 0;
while (i < s.length && j < t.length)
{
if (s.data[i] == t.data[j])
{
i++;
j++;
}//匹配失败
else
{
i = i - j + 1;
j = 0;
}
}
if (j == t.length)
{
return true;
}
else
{
return false;
}
}
int main()
{
SqString s = { "aaaaab",6 };
SqString t = { "aaab",4 };
printf("%d", BF(s,t));
return 0;
}
下面是运行结果