When I was testing my code, I found that my code gives a segmentation fault using the large dictionary and is unable to load/open the small dictionary. Is this a result of my load function? Thanks in advance.

My code:

// edited out per academic honesty

I debugged your code and I am a little bit puzzled. With your code, both large and small loaded fine and with no Segmentation faults.

I did find some lines that might cause logic error though. I am going to refer to lines based on the code block you provided. For example:

typedef struct node                                // line #002

trav->children[l - 'a'] = calloc(1, sizeof(node)); // line #116

1.- In the load function the code checks for a negative index when an apostrophe is found. Line 123:

else if (l == '\'' && trav->children[l - 'a'] == NULL)

If l == '\'' then l is 39 (apostrophe's ASCII code) and 'a' is 97, so

trav->children[l - 'a'] // is the same as

trav->children[-58]     // which might cause a Segmentation fault.

2.- The boolean is_word is loaded as true in a different place than it is checked if is true. I also noticed that all words are marked as misspelled even if you check a dictionary against itself. For example:

./speller dictionaries/small dictionaries/small

That will spell-check the small "text" against the small "dictionary". And it should show as everything correctly spelled.


I suggest you change line 123 to something like:

else if (l == '\'' && trav->children[26] == NULL)

And line 62 to something like:

return trav->children[ind]->is_word;
  • Thank you for your answer! However, my code is still throwing a segmentation fault. I wonder if it is my implementation of unload, which I did not include here. I will edit my question and include my function 'unload'. – SuperNovaCoder Oct 27 '16 at 15:26
  • See update above – SuperNovaCoder Oct 27 '16 at 18:56
  • I am sorry. I could not check your updated code yesterday. Do you still have the segmentation fault? – Ricardo David Antonetti Oct 28 '16 at 13:19

You must log in to answer this question.

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