Im having troubles with the hashtable in pset5, in the part where you check wether a word is in the dictionary. My code looks as follows:

bool check(const char* word)

int n = strlen(word);
char lower_word[LENGTH+1];

for (int i=0; i < n; i++)
    lower_word[i] = tolower(word[i]);

//end with a \0 to state that the word is finished
lower_word[n] = '\0'; 

int hash_value = hash(lower_word);
node* check_node = hashtable[hash_value]; 

if (check_node == NULL)

    return false;

//search dictionary: while not at end of dictionary, compare current dictionary word with inputted word
while (check_node != NULL)

    if (strcmp(check_node->word,lower_word) == 0)
        return true; // found it!

    //if not found, go to next word
    check_node = check_node->next;  

//word not found :(
return false;

It returns that all words are misspelled. I think the problem lies in the line where I define check_node. Can somebody help me with this?

EDIT: The problem was indeed in the load function, this code works correctly.

  • I'm facing a similar issue, what problem did you find in the load function and how did you debug it? Oct 9, 2015 at 17:52

1 Answer 1


Without seeing the load and hash functions, it's almost impossible to know what's wrong. It could be that the hash function isn't giving the same result for the same word each time, or the word that is being processed has some stray characters or non-alphas attached, which could change the hash. Or, there's a problem with how the load is being done.

You should run the program in gdb with a small dictionary and trace out what is happening, or insert some printf statements in load and check to see exactly what the word variables contain, what hash is being generated for the same word in load and in check, and to see which return false is being triggered in check. This will give you a clue what is happening and you can troubleshoot from there.

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

You must log in to answer this question.

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