I'm using a 64 bit system with Ubuntu. For every program I write that does anything more than
printf("name of program + copyright\n");
when I run it the konsole always says : "core dump segmentation fault"
or something like that , what could be the problem
segmentation fault
- bloodhound23
- Member
- Posts: 115
- Joined: Wed Jan 23, 2008 7:13 pm
- Contact:
segmentation fault
I thought I wasn't thinking, I thought wrong.
- Brynet-Inc
- Member
- Posts: 2426
- Joined: Tue Oct 17, 2006 9:29 pm
- Libera.chat IRC: brynet
- Location: Canada
- Contact:
I suppose the real question is.. what "more" are you doing after the printf?
Seriously man, http://catb.org/~esr/faqs/smart-questions.html
Seriously man, http://catb.org/~esr/faqs/smart-questions.html
i remember the good old days when i programmed on windows and it accepted code like this
then i switched to linux and it segfault'd
Code: Select all
char *c;
gets(c);
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
Coping with Segmentation faluts
Coping up with segmentation faults
-----------------------------------------
You should learn how to use gdb properly ...
when compiling use the g flag .. eg gcc -g <urfile> -o<outputfile>
The run ur program in gdb ... eg gdb outputfile ...
at the gdb prompt use break <line no or func name > to use breakpoints
... use next and step to go through your code ... up and down etc for going up and down frames ... use print <variable name > to view variables in gdb prompt ..use list view source file etc .... There is more to gdb than this ... i just gave a quick summary ... use gdb effectively to sqat out your bugs
-----------------------------------------
You should learn how to use gdb properly ...
when compiling use the g flag .. eg gcc -g <urfile> -o<outputfile>
The run ur program in gdb ... eg gdb outputfile ...
at the gdb prompt use break <line no or func name > to use breakpoints
... use next and step to go through your code ... up and down etc for going up and down frames ... use print <variable name > to view variables in gdb prompt ..use list view source file etc .... There is more to gdb than this ... i just gave a quick summary ... use gdb effectively to sqat out your bugs
-
- Member
- Posts: 566
- Joined: Tue Jun 20, 2006 9:17 am
It should segfault for your program's and your good .... When you declare a pointer like that it is pointing to a random address ... It will seg fault in windows also ... but you may be able to run it in dos using turbo C or some legacy compilers ... you should always use malloc before using gets(c) .... You have made a conceptually erraneous statement ....Pyrofan1 Posted: Mon Feb 11, 2008 4:53 am Post subject:
i remember the good old days when i programmed on windows and it accepted code like this Code:
char *c;
gets(c);
then i switched to linux and it segfault'd
Means you still don't run your compiler with proper warnings enabled, or you would have caught that problem long before it segfaults.Pyrofan1 wrote:i remember the good old days when i programmed on windows and it accepted code like this [...] then i switched to linux and it segfault'd
Every good solution is obvious once you've found it.