0

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:

enter image description here

1 Answer 1

-1

Use gdb to check the values of that node.

2
  • I don't mean to cause trouble, but how is that an accepted answer? First of all it just says to use gdb on a node, and moreover the questionnaire already has used gdb per his question. Anyway.
    – ChrisG
    Commented Aug 19, 2015 at 8:00
  • Ideally he will troubleshoot the issue himself, rather than a complete answer I am just giving him a direction to overcome his current brick-wall. He did use gdb but only as far as to identify which line the segfault occurs.
    – Glen
    Commented Aug 19, 2015 at 20:13

You must log in to answer this question.

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