typedef struct{
char *str;
int maxLength;
int length;
}DString;
//查找主串S从start始的子串T,成功则返回T在S中的首字符位置,失败则返回-1
int BFIndex(DString S, int start, DString T)
{
int i = start, j = 0, v;
while ((i < S.length)&&(j < T.length))
{
if(S.str[i] == T.str[j])
{
i++;
j++;
}
else
{
i = i - j + 1;
j = 0;
}
}
if (j == T.length)
{
v = i-T.length;
}
else
{
v = -1;
}
return v;
}