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.