0

My code works fine when I don't use the large dictionary, but when I do use it, I get a segmentation fault. When I use GDB, the problem is so far into the dictionary that it would take forever to get to the part of my code that causes the seg fault. My code is below. I have implemented a trie whose leaf nodes branch off into linked lists that contain possible word endings, because I wanted to see if this would take less time to load because I am not instantiating a new trieNode for every single letter. DICTIONARYSIZE is the number of layers to the trie. I use trieNavigate() both to load and to check, and I know that works properly.

I only get a seg fault now with a large dictionary. I don't know why though... It works with supercalifragilisticexpialidocious.

EDIT: My code can check words correctly now

[Code removed to comply with academic honesty code]

1

THis should get you started. I ran your code using a tiny dictionary (cat, cater, car) as both the dictionary and the test text and was able to duplicate the seg fault. I located the following issue. Look at this code near the end of your check() function.

else
{
    while (linkedListCrawler->next != NULL);
    {
        linkedListCrawler = linkedListCrawler->next;

        if (strcmp(linkedListCrawler->word, restOfWord) == 0)
        {
            return true;
        }
    }
    return false;
}

When I ran against my test data, I found that the strcmp() was causing the seg fault. The line before reassigns linkedListCrawler to the next one in the list, but after doing this, you don't check to see if linkedListCrawler->word is NULL. In fact, I found that it could be NULL and when it was, it tripped the seg fault.

No idea what other issues remain, if any, but this will get you going.

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

2
  • The problem was this block of code: if (trieCrawler->linkedListPointer == NULL). I changed it to if (index < wordLength). I'm still getting a seg fault though. – David Sep 12 '15 at 19:46
  • No, that block of code was supposed to be if (index == wordLength - 1) – David Sep 12 '15 at 19:58
0

I found out what was wrong. I wasn't checking for an apostrophe properly. I didn't need to convert to a string and use strcmp().

if (strcmp(stringOfC, "\'") == 0) { letterValue = 26; }

I could just compare the characters:

if (c == '\'') { letterValue = 26; }

No more seg faults now.

You must log in to answer this question.

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