-1

I've been stuck with this for a while. I can't really figure out why I'm getting this message: I get the error message: "Segmentation fault (core dumped)" when I first compile gcc my_program.c and then run it ./a.out my_program.c

Main file: https://i.stack.imgur.com/usdsc.jpg Header file: https://i.stack.imgur.com/jJeuu.jpg

I can't for the life of me figure out where the problem is since C isn't really my friend and it doesn't tell me where the error is in the code.

dark_light
  • 41
  • 5
  • 2
    https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question – Thomas Feb 22 '21 at 16:35
  • 7
    Please paste your program here (in your post). – babon Feb 22 '21 at 16:37
  • try to compile it using `gcc -g my_program.c` and run it using gdb, it will tell you where it fails ( see https://stackoverflow.com/questions/2876357/determine-the-line-of-code-that-causes-a-segmentation-fault ) – ShellCode Feb 22 '21 at 16:41
  • I just thought that if I post my own code here, maybe I will be "plagiarizing" my own code when I submit it later? Cause the school has that kinf of system, I think. – dark_light Feb 22 '21 at 16:41
  • @dark_light We can't help you if we can't run the code – apilat Feb 22 '21 at 16:43
  • The claim that C "doesn't tell me where the error is in the code" is absolutely false. It created a core dump for you. It even told you that it created a core dump. The fact that you don't know how to use that core dump to see exactly what the error was and where it occurred is not a failing of the language. – William Pursell Feb 22 '21 at 16:52
  • In `printList`, you reference `node->next` when `node` is NULL. Don't do that. – William Pursell Feb 22 '21 at 16:55

1 Answers1

0

It's probably line 37 in the main file. You should change printlist(node) to printnod(node). That ought to fix it.

gojira
  • 24
  • 5