I have spent hours checking my code but still couldn't figure out which part went wrong. The program executed without throwing errors but the misspelled words identified were wrong. I think the problem is probably somewhere in my load or check function but I couldn't find out where the problem is.
I have removed some parts of the code and comments which I think are not that relevant to keep this within the 'reasonable' actions. Please tell me if I need to remove more of it (or moderators just edit for me).
Below is my load function (using trie) :
bool load(const char* dictionary)
{
// load dictionary
...
root = malloc(sizeof(node));
node* cursor = NULL;
do
{
cursor = root;
for (int c = fgetc(dic); c != '\n'; c = fgetc(dic))
{
if (isalpha(c))
{
if (cursor->children[c - 'a'] == NULL)
{
cursor->children[c - 'a'] = malloc(sizeof(node));
}
cursor = cursor->children[c - 'a'];
}
else if (c == '\'')
{
if (cursor->children[26] == NULL)
{
cursor->children[26] = malloc(sizeof(node));
}
cursor = cursor->children[26];
}
}
cursor->is_word = true;
wcount++;
} while (fgetc(dic) != EOF);
// close file
...
}
When run directly using ./speller, I would receive the following result :
WORDS MISSPELLED: 11515
WORDS IN DICTIONARY: 143091
WORDS IN TEXT: 19190
TIME IN load: 0.04
TIME IN check: 0.01
TIME IN size: 0.00
TIME IN unload: 0.04
TIME IN TOTAL: 0.09
It seems all the words in dictionary and text are calculated correctly when I compared it with staff's solution, but the words identified as misspelled are wrong.
Edit : Removed check function as it's not relevant.
And the following result when I used check50 :
:) dictionary.c, dictionary.h, Makefile exist
:) speller compiles
:( handles most basic words properly
\ expected output, but not "\nMISSPELLED WORDS\n\nThe\nquick\nfox\n..."
:) handles min length (1-char) words
:) handles max length (45-char) words
:) spell-checking is case-insensitive
:) handles possessives properly
:( handles substrings properly
\ expected output, but not "\nMISSPELLED WORDS\n\nca\ncats\ncaterpi..."
So which part of the code is wrong? I'm quite clueless and really appreciate your help in pointing out where I should change / look for the problem.
Thank you.
// if it's not a word ...
– Kareem♦ Mar 28 '15 at 16:14load
andcheck
! – Kareem♦ Mar 28 '15 at 16:41