If you paste this code at https://www.onlinegdb.com/ , then click “Debug” and then type run
into the gdb window, it takes you to the line that creates the error. (You can click the “help” button near the Debug button to get instructions on how to further use this tool. Or you can google “gdb debugging” or “visual studio debugging” for further help.)
The error is on your scanf
line. If you google “scanf”, you’ll probably notice that int arguments pass the address of
the int. So you need &x
, not x
. Your program has other errors, as well. I suggest you make use of the help button mentioned above for the debugger, step through your program, and watch what’s happening. For instance, you’ll notice your program immediately exits once you fix the first issue. I imagine you’ll want a loop to prevent that. Further, in your pop, you’re specifically checking if top==null
, and then dereferencing it (top->data
) if it is. This is guaranteed to be illegal. This is something you can check by running the debugger, selecting pop, and then printing the value (in the debugger) that your program is trying to access (print top->data
in the gdb window)
7
solved c code file is crashing and there is no error while compile [closed]