The load function is loading the dictionary correctly (to the best of my knowledge). I have confirmed this by stepping through it in the debugger and watching the values change in the trie in the local variables.
My strategy for loading is...
iterate through each character in dictionary if character == '\n' change cursor->is_word to true reset cursor to root get an alphabetic index (0-26, 26 for " ' ") if cursor->children[alpha_index] == NULL create new node and assign to cursor->children[alpha_index] move cursor to cursor->children[alpha_index]
Problem is during the check function only the last word in the dictionary has is_word set to true.
dictionary.txt: cat cater example.txt: ca cat cats cater caterlo ./speller dictionary.txt example.txt MISSPELLED WORDS ca cat cats caterlo
I am getting similar results when I add words to the dictionary and example text.
When step debugging through the check function, when I reach the letter 'T' node I would expect the value of that node's 'is_word' property to be true but it shows false. Like I mentioned earlier this was not the case when stepping through the load function.
However, when I get to the 'R' node, I get the expected is_word: true. When I put 'cater' before 'cat' in the dictionary, node 'T'->is_word == true and node 'R'->is_word == false.
I can't figure out why it is being loaded correctly and then when it is being check it's like none of that worked properly with the exception of the last word in the dictionary.
I've spent two full days on this and need some fresh eyes. I'm super stuck on this one. Uploaded my code to Github.
Thanks for the help in advance!