【发布时间】:2020-05-22 11:46:30
【问题描述】:
这是我在这里的第一篇文章,我需要帮助。 拼写器对 lalaland.txt 的输出是 958 个单词,但应该是 955。(3 x "i'd")。 我曾尝试硬编码“i'd”,但输出约为 850。 (程序拒绝了所有的“我会”)。 tolstoy.txt - 13117,但必须是 13008,大多数单词是两个字母(Ha、ha、ga、Ma、I'd 等)。 同时同一单词的其他部分通过检查。 所有其他文本的情况相同。程序无缘无故地通过和拒绝相同的单词。 我不知道发生了什么。
这是我的负载();
bool load(const char *dictionary)
{
FILE *inputFile = fopen(dictionary, "r");
if (inputFile == NULL)
{
return false;
}
while (true)
{
node *n = malloc(sizeof(node));
if (n == NULL)
{
return 1;
}
n->next = NULL;
int sc = fscanf(inputFile, "%s", n->word);
if (sc == EOF)
{
free(n);
break;
}
int bucket = hash(n->word);
if (table[bucket] == NULL)
{
table[bucket] = n;
}
else
{
n->next = table[bucket]->next;
table[bucket]->next = n;
}
sizeCount++;
}
fclose(inputFile);
return true;
}
和检查();
bool check(const char *word)
{
int i = hash(word);
if (table[i] == NULL)
{
return false;
}
struct node *checker = malloc(sizeof(node));
checker = table[i];
while (true)
{
if (strcasecmp(checker->word, word) == 0)
{
return true;
}
if (checker->next == NULL)
{
break;
}
checker = checker->next;
}
free(checker);
return false;
}
【问题讨论】:
-
看起来像是复制/粘贴事故;实际检查功能未发布。
-
第一次发帖失败))。谢谢。
标签: cs50