首页 > 解决方案 > strtok 不会继续下一次迭代

问题描述

SpellingSuggestion* spellingCheck(){
    char text [] = "iam afraid youare about to become teh immexdiate pst president of teh eing alive club ha ha glados";
    char* filePath = "/Users/ronijackvituli/Desktop/Assignment/dictionary.txt";
    char* pch;
    HashTable* ht = initTable(WORDS, HASH_FUNCTION);
    SpellingSuggestion* head = NULL , *list = head;
    if(parseWordsToTable(filePath, ht)){
        pch = strtok(text, " "); ..
        while (pch != NULL) {
            if(head == NULL){
                head = BuildNodeSuggestion(pch, getWordSuggestions(ht,pch));
                list = head;
            }else{
                list->next = BuildNodeSuggestion(pch, getWordSuggestions(ht,pch));
                list = list->next;
            }
            pch = strtok(NULL, " "); //Does not move on to the next iteration
        }
    }else{
        printf("THE WORDS NOT INSERT TO HASHTABLE.\n\n");
    }
    return head;
}

pch 将第一个单词“iam”发送到我构建的函数中,一切都正确返回,但一旦到达该行

pch = strtok (NULL, "");

移动到下一个迭代,即“害怕”这个词,他没有这样做,直接 pch = NULL

标签: cstringstrtok

解决方案


推荐阅读