0

Im not quite sure what is the problem with checking the words in the dictionary against loaded texts. All words within in the loaded txts return mispelled even with my dictionary loaded with the right number of words. I searched through other responses similar to this question but i couldn't find anything helpfull to debug my dictionary.c. Could someone (anyone) please point me into the right direction to fix this? Any help would be appreciated.

UPDATED code, with applied fixes.

[code hidden]

UPDATE: I have followed the first three pointers Cliff has given me(and they work as expected), but I am still having trouble implementing number 4. Below is what what I've tried, but to no avail I am still having the same output as before.

int s = strlen(word);
char checker[LENGTH + 1];

for(int i = 0; i < s; i++)
    checker[i] =  tolower(word[i]);

checker[s] = '\0';    
2
  • Can you post the other changes you made so we can see what you're working with? – Cliff B Apr 14 '16 at 16:54
  • I updated the code. Thanks for replying! – foreodessa Apr 14 '16 at 19:28
2

In your load, when your hashtable[key]->next isn't null, you do this:

    new_word->next=head; 
    head = new_word;

what is head at this point? Last time you set it, it was for the first node in your linked list. As such, you are overwriting the first node in that bucket and end up throwing away some words.

Shouldn't you be using hashtable[key]->next? And not head?

1
  • For learning's sake ill answer your first question. Head at this point serves as the first node of the linked list. Meaning that I have "two" seperate linked lists that my key is pointing to, Head and new_word. I thought I was chaining the head to the new words added, not over write them! Thanks for your help. – foreodessa Apr 15 '16 at 7:39
1

Here are some pointers in the right direction:

  1. The large dictionary is hardcoded. Should be using parameter passed to load() as the dictionary.
  2. All words are hashing to 0 because word is empty. (new->word vs. word)
  3. Word count is off by 1. Code reads a line from dictionary file, processes it, and then checks for EOF. This results in one extra word in the count and last word being processed twice.
  4. In check(), no end of string marker set in checker[], causing strcmp to always fail.

There is at least one more problem, but this will get you going. :-)

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

1
  • Cliff can you (or anyone) explain why the problem persists, even after I declared a null after each string on the check function? – foreodessa Apr 14 '16 at 14:41

You must log in to answer this question.

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