I have been using Slack exclusively up to this point but, I figured I would give SE a try (plus my boss is out today and I have some free time.)

I am working on PSET 5's check(). The error that I receive with the below code is a segmentation fault. After running GDB I assume the segmentation fault occurs at the if (newNode->children[c] == NULL). I unfortunately can not post the GDB deets as I do not have access to them at work. So I have three questions that will surely lead me in the right direction.

1_This has to due with the case insensitivity. If I understand correctly, we do have to take some action to make sure all the letters are lowercase. Is that correct? If so, would a to lower function after the first else work, for example something like

(tolower(c) - 'a')

2_This has to do with the go to corresponding element in children. Is the below correct? The mini dictionary that I implemented has a first word of 'baby' and I am fairly certain it is not making it past the first letter which leads me to believe I have made the mistake early on.

3_I am seeing now where I could have another mistake but I will not be able to check it until I get home but, anyhow, I think the isWord line is incorrect as well. Should it rather be if (newNode->isWord == 0), something like that? I am not following the instructions with my current code below because I am not checking if the isWord is true.

Let me know what you think, community! Thanks in advance.

EDIT: I have added the tolower(c) and the edited the isWord line. Still getting a segmentation fault and still confused.

        if (newNode->children[c] == NULL)

EDIT EDIT: The problem has been solved /code taken down.


A missing "tolower"? When i is 0 and word is Soup, you'll have a problem with c set to c - 'a'. You mention else (tolower(c) - 'a') but I don't see "tolower" in your code snippet.

  • Sorry, that was supposed to be worded like this, "would a tolower function after the first else word, for example {else (tolower(c) - 'a') }". I see what you mean how it would not though. – SozDaneron Nov 6 '15 at 14:23
  • Communication is an art :)...... It would help. If word[0] is 'S', then " c = c - 'a' " evaluates to -14. BUZZ. Segfault at children[c]. – DinoCoderSaurus Nov 6 '15 at 15:13
  • I am still getting a segmentation fault, and I think it's still at the same line. Meaning, at the newNode->children[c] == NULL line – SozDaneron Nov 7 '15 at 12:47
  • If there are no words in your dictionary that start with 'a', would root->children[0] be initialized to NULL or would it hold junk from the stack? – DinoCoderSaurus Nov 7 '15 at 14:04
  • I am not sure how to answer the question. When I try this code with my mini dictionary, the words include baby, boop, foo, yeah, the terminal shows the words 'MISSPELLED WORDS' and that is follow by an error that reads 'segmentation fault (core dumped).' – SozDaneron Nov 7 '15 at 15:30

So, Dino, you were essentially right. Although I was using calloc, the way I was initilizing/declaring in load and check contradicted the two functions. It was a "scope problem" where newNode(tracker) was indeed being declared rather than initialized.

  • Great news, DSOZ. Why don't you give your answer a check? Others may find that very useful information. And it helps keep up with the housekeeping. – DinoCoderSaurus Nov 11 '15 at 0:06
  • You can't vote for your own post. That would be housekeeping on another level. – SozDaneron Nov 11 '15 at 13:22
  • Yes you can. cs50.stackexchange.com/help/self-answer – DinoCoderSaurus Nov 11 '15 at 13:37
  • I tried too again, and i was prompted with a red warning. I then up clicked your answer to see if there was a problem and that worked. I tried to void that answer by downclicking but that gave it a -1...so let's just keep it as is. Props to curiouskiwi for helping me anyhow, curiouskiwi +. – SozDaneron Nov 11 '15 at 14:07
  • Sorry, when I said "give your answer a check", I meant you should "accept" your answer. – DinoCoderSaurus Nov 11 '15 at 14:27

You must log in to answer this question.

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