我希望我不会因此很快被否决,但我有一个正在为学校工作的项目,我必须在其中构建一个拼写检查器。我决定使用 trie,它似乎可以正常工作,但我有一个我找不到的错误。我认为问题在于以下,
bool load(const char* dictionary)
{
if (!rootNode)
{
rootNode = trieNodeCreate();
if (!rootNode)
{
printf("could not allocate root node");
return false;
}
}
// Open the file
FILE* fp = fopen(dictionary, "r");
if (fp == NULL)
{
printf("could not open dictioanry %s\n", dictionary);
return false;
}
int index = 0;
for (int c = fgetc(fp); c != EOF; c = fgetc(fp))
{
char word[LENGTH];
if (c != '\n' )
{
word[index] = c;
index++;
}
else
{
trieWordInsert(word, rootNode);
index = 0;
wordCount ++;
}
}
fclose(fp);
if (wordCount)
{
return true;
}
return false;
}
但我一直找不到它。该项目的其余部分可以在