0

I receive a segfault at this line of code

    if (pathCheck -> children[charVal] == NULL) {
    
        return false;
    }

pseudocode buildup:

initialise pathCheck to NULL 

while character is not \0

initialise character as character of input word

initialise value of character (c - 'a')

change to lower

then check if NULL (as above) 

Any ideas?

1
  • I have run gdb which gives me the line, then valgrind which claims I have no leaks Commented Aug 14, 2014 at 15:44

1 Answer 1

0

There was no allocated memory for the node pointer. I fixed this by assigning memory for the node using:

malloc root = malloc(sizeof(node));
node* pathCheck = root;
6
  • If this is supposed to be an answer, please clarify how you solved the problem once you found there was no memory allocated for the pointer. Currently it's unclear if this relates to the problem or the solution.
    – Air
    Commented Aug 14, 2014 at 17:23
  • Sorry, assigned memory for the node using malloc root = malloc(sizeof(node)); node* pathCheck = root; Commented Aug 14, 2014 at 17:29
  • OK - I added that into the answer. For future reference, better to clarify by editing than by commenting, since comments are considered second-class citizens on Stack Exchange (some explanation of what that means here and here). You can (and should) accept your own answer if you fully solved the problem.
    – Air
    Commented Aug 14, 2014 at 18:07
  • 1
    Sure thanks! Still assimilating to the StackExchange culture Commented Aug 14, 2014 at 18:14
  • @AdamWilson Remember to "accept" this answer. Commented Aug 15, 2014 at 13:19

You must log in to answer this question.

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