我想知道在另一个字符串(干草堆)中计算一个字符串(针)出现次数的最快方法是什么。我这样做的方式是:
int findWord(char * file, char * word){
char *fptr;
char * current = strtok_r(file, " ,.\n", &fptr);
int sum = 0;
while (current != NULL){
//printf("%s\n", current);
if(strcmp(current, word) == 0)
sum+=1;
current = strtok_r(NULL, " ,.\n", &fptr);
}
return sum;
}
使用更复杂的算法(Boyer-Moore)会更快吗?谢谢