c - 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
解决方案
推荐阅读
- python - 如何在kafka消费者中读取和处理高优先级消息?
- database - 在不同网络上的多个设备中使用静态 IP 地址
- gitlab - 用于 CI 和计划 SAST 的 GitLab 管道 (.gitlab-ci.yml)
- excel - 基于主键的行中的唯一值创建工作表
- coq - 我知道定义有限数类型的两种方法。有什么词可以区分这两者吗?
- javascript - 为什么第二个 if 语句的行为是这样的?
- vba - MS VBA 编辑器隐藏成员提示
- python - ValueError:值太多但需要所有变量
- python - 如何从图表中抓取数据?
- c++ - 使用 unique_ptr 使我的二叉树类可迭代