When I run the program it gives me a segmentation fault, the most annoying thing is that it doesn't tell me where this error occurs? Is there any way or an option in gcc, where I can show an option to show where this error occurs?
When I run the program it gives me a segmentation fault, the most annoying thing is that it doesn't tell me where this error occurs? Is there any way or an option in gcc, where I can show an option to show where this error occurs?
Yeah, run it in the debugger.
gcc -g prog.c
gdb a.out
run
Sit back and wait, or interact with the program as normal.
When it blows up, use the 'bt' command to reveal all.
If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
If at first you don't succeed, try writing your phone number on the exam paper.
With gdb you can step through your code and it'll abend at sigsegv.
the program takes an input file from stdin , so how do I modify this?
will make gdb redirect blah.txt to stdin in your application.Code:set arg < blah.txt
--
Mats
Compilers can produce warnings - make the compiler programmers happy: Use them!
Please don't PM me for help - and no, I don't do help over instant messengers.