+ 1
No output in Code Playground (C code)
I decided to redo the Josephus Problem Challenge in C because I haven't used that language for years, and even back then I've only written a handful of codes. However, the code works (almost) like a charm when compiled with GCC, but after copy & pasting it into the Code Playground and running it there, it only says "No output". Any idea why? (It's not because of the command line input, I tried commenting it out.) Furthermore, does anyone know why I get a segmentation fault if count == 1? https://code.sololearn.com/c3IxF1C58V5i/?ref=app
2 odpowiedzi
+ 2
Line 23 add:
head->next = head;
to fix segmentation fault for count of 1.
To fix fault in playground to get output, change line 60 & 61 to:
man *hold = current->next->next;
free(current->next);
current->next = hold;
free makes the memory unavailable so your access faulted.
+ 1
Aaah, of course. Such a stupid mistake in line 60/61, that's what you get for coding at night.
Thank you very much!
edit: I changed "hold" to "sentenced" because it fits the context. free(sentenced) in the kill-function sounds unintentionally philosophical, lol