I am getting a segmentation fault in a while loop for my check function. I don't know why it is happening and need some help understanding my error.
This is my function:
bool check(const char* word)
{
//lower case the word
int wordLength = strlen(word);
char temp[wordLength + 1];
strcpy(temp, word);
for(int i = 0; i < wordLength; i++)
{
if(isalpha(word[i]))
{
temp[i] = tolower(temp[i]);
}
}
temp[wordLength] = '\0';
int hashIndex = indexWord(temp);
node* thisNode = hashTable[hashIndex];
while(thisNode->next != NULL)
{
if(strcmp(temp, thisNode->word) == 0)
{
return true;
}
}
return false;
}
According to the GDB it occurs on the while loop as you can see here: