0.结构体
#define MAXSIZE 100
type struct{
char str[MAXSIZE];
int length;
}seqstring;
1.朴素的模式匹配算法
int index(seqstring p, seqstring t)
{
int i, j, succ;
i = 0; succ = 0; //succ为成功匹配的标志
while ((i <= t.length - p.length) && (!succ))
{
j = 0; succ = 1;
while ((j <= p.length - 1) && succ)
if (p.str[j] == t.str[i + j]) j++;
else succ = 0;
++i;
}
if (succ) return i - 1;
else return -1;
}