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?

  • I have run gdb which gives me the line, then valgrind which claims I have no leaks – Adam Wilson Aug 14 '14 at 15:44

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;
  • 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 Aug 14 '14 at 17:23
  • Sorry, assigned memory for the node using malloc root = malloc(sizeof(node)); node* pathCheck = root; – Adam Wilson Aug 14 '14 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 Aug 14 '14 at 18:07
  • 1
    Sure thanks! Still assimilating to the StackExchange culture – Adam Wilson Aug 14 '14 at 18:14
  • @AdamWilson Remember to "accept" this answer. – Luke Van In Aug 15 '14 at 13:19

You must log in to answer this question.

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