• Segfault when running specific function - C
    9 replies, posted
-snip-
Problem is here: [code]prev->next = replacement->head;[/code] You initialise prev as a null pointer, then attempt to dereference it. [editline]26th October 2017[/editline] Also, you do: [code]next = next->next;[/code] Without checking if next is valid.
-snip-
Both those fixes should work.
-snip-
[QUOTE=Sexy Frog;52825796]Yeah, what happens when I run it with those changes is that it runs in the terminal but it doesn't seem to reach a conclusion and I have to ctrl+c to force stop it. interestingly enough, however when I put a return at the end of the else statement like so: [code]else { prev = curr; curr = next; next = next->next; return; } [/code] it seems to yield a result (granted not the one I'm looking for and does not segfault). So I'm imagining everything is hunky dory until it reaches a certain point in the LL.... [img]https://i.imgur.com/7BpiLTe.png[/img][/QUOTE] Have it print to terminal without the return and see what it gives you.
-snip-
Hmm, if all else fails print out each variable to see if things are even being set to what they're supposed to be in the first place.
Why did you snip everything What about if someone else needs help on it...I really think this should be a bannable reason to snip questions solved...
Yeah it should be, there is no reason for it.
Sorry, you need to Log In to post a reply to this thread.