Timeline for Cannot clear segmentation fault in load pset5
Current License: CC BY-SA 3.0
4 events
when toggle format | what | by | license | comment | |
---|---|---|---|---|---|
Sep 22, 2015 at 11:09 | comment | added | ChrisG |
Then that's why you get the segfault. If you declared table as node* table[n] , table is just a pointer for node s. So since it's not a node itself, it doesn't have the next attribute itself. So when try to load your first node , table[value] points to NULL , and since you try N->next = table[value]->next; the segfault occurs. You try to access NULL->next
|
|
Sep 22, 2015 at 10:21 | comment | added | buitri84 | Thanks ChrisG, but that doesn't answer my question: - regarding fgetc(ptr) != EOF, yes I did realized it was missing the first character (so that I only got 'at' instead of 'cat', but that did not cause the segmentation fault. I tried it just because I wanted to be really sure the while() loop does not run 1 time too many (but I still didn't succeed). - On the table declaration, I did not show the code but it was indeed declared globally as node *table[n]. So my global declaration plus the for() loop to malloc() the table do exactly the same thing as you were saying. | |
Sep 21, 2015 at 18:03 | history | edited | ChrisG | CC BY-SA 3.0 |
added 435 characters in body
|
Sep 21, 2015 at 10:49 | history | answered | ChrisG | CC BY-SA 3.0 |