偶尔看到的大名鼎鼎的KMP算法。
wiki在此
int kmp_search(char *needle, char *haystack) {
if(NULL==haystack || NULL==needle)
return -1;
int nl=strlen(needle);
int *failtable= (int *)malloc(nl*sizeof(int));
if(NULL==failtable)
exit(-1);