I think I wrote dictionary properly but my problem is that speller reads the first word of the text only then gets to the space after and just stops without ending. It is confusing since as far as I know load works properly since it goes through the text after loading the dictionary. The first space after the first word goes inside the for loop

for (int c = fgetc(fp); c != EOF; c = fgetc(fp))

but it is not even reach the

     else if (index > 0)

which would begin the spell checking process on the word. I know this because I put printf statements inside every condition to see what it was doing. I even tried changing the else if condition to an else condition which would force it to go inside the condition since I know that it didn't go inside any of the other conditions but it still didn't go. It just stops.

here is my implementation of dictionary: http://pastebin.com/Vcd6HHgf

node is defined in dictionary.h

typedef struct node
char node [LENGTH + 1];
struct node* next;

1 Answer 1


There are a couple of issues. First, your unload function has problems and is erroring out. Suggest that you put return true; in as the first line to bypass it until you sort out the other issues. Then, you can come back and make it work correctly.

Now, the main problem. Your load function has a serious problem. It creates a single node and reuses it over and over. Every time a word is processed, the prior word is overwritten in the tree. You end up with pointers in the root array, but everything points at that node. It also means that the only actual word in the dictionary is the last word processed. You need to alter your code to create a new node every time a word is processed.

These are the significant problems, there may or may not be more, depending on what you change to address these.

As a side note, you have a break statement following a return statement. The break statement is dead code (can never be executed) and can be removed. It's dead because executing the return immediately transfers control to the calling code and anything that follows a return will never be reached or executed.

If this answers your question, please click on the check mark to accept. Let's keep up on forum maintenance. ;-)

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .