I'm not sure what exactly is wrong with my code. I ran it through Valgrind, which says "Looks like you're trying to use a variable that might not have a value? Take a closer look at line 145 of dictionary.c" specifically referring to this line of my code in the Check section:
while(strcmp((*cursor).word, new_array_for_textword) != 0)
--- see my attached code for more info. I don't get why it is wrong, as the logical steps seem fine to me. Appreciate it if anyone could let me know what's wrong, thanks so much.
bool check(const char *word)
{
//calculate length of the text word
int wordlength = strlen(word);
//allocate space for the new array in CHECK
char new_array_for_textword[wordlength + 1];
//copy word from text to new array so that we can make them all lower case
for (int i = 0; i < wordlength; i++)
{
new_array_for_textword[i] = tolower(word[i]);
}
//in the array_for_textword you need to add \0
new_array_for_textword[wordlength + 1] = '\0';
//hash the word
int hashnumber = hash(new_array_for_textword);
//check the hash tables are not empty
if(hashtable[hashnumber] == NULL)
{
return false;
}
node *cursor = hashtable[hashnumber];
//compare both strings, as long as they are not the same, the node will proceed, until it hits the same strings
while(strcmp((*cursor).word, new_array_for_textword) != 0)
{
cursor = (*cursor).next;
if(cursor == NULL)
{
return false;
}
}
return true;
}