Re: Code fails with Segmentation Fault



Tom St Denis wrote:
Bill Medland wrote:
Vlad Dogaru wrote:

Hello,

I am trying to learn C, especially pointers. The following code
attempts to count the appearences of each word in a text file, but
fails invariably with Segmentation Fault. Please help me out, I've
already tried all my ideas. Also, please do comment on my coding style
or other aspects. Thank you.

First of all use a debugger to find out where the seg fault occurs.

I agree with you here. Above all, learning to use gdb [or similiar
tool] is very valuable. Learn to develop with it on a routine basis as
it will save your behind more often than not.

It's likely that a beginner is often put off by a complex program like
gdb. A graphical front-end like ddd might alleviate the learning curve.

But for very small programs, such as those you write when you start
learning C, it might be better to mentally "run" the program, rather
than fire up a debugger at a hint of the least problem.

However I agree that as a program gets larger, a debugger becomes
increasingly handy, especially if the code is written by someone else.

.



Relevant Pages

  • Re: gdb vs fortran RTL -- fight for SIGSEGV
    ... it segfaults with a "Segmentation fault" which can be trapped ... When I compile it under ifort, ... However, gdb still successfully traps this, so it can be debugged. ... that's why then the debugger cannot catch the signal. ...
    (comp.unix.programmer)
  • Re: for and arrays
    ... For example, in gdb it shows: ... ...And you are your best debugger. ... if Richard is talking about file sectors and segments and the internals of ... files like symbol tables and headers I might just be interested in learning ...
    (comp.lang.c)
  • Re: seg fault
    ... I've never used a debugger, ever, but I thought I'd give this a go. ... First problem was to get gdb for Windows, but 10-15 mins on google and ... or -ggdb switches I use for gcc. ... where bugs could be due also to errors in the compiler, ...
    (comp.lang.c)
  • Re: seg fault
    ... I've never used a debugger, ever, but I thought I'd give this a go. ... First problem was to get gdb for Windows, but 10-15 mins on google and ... or -ggdb switches I use for gcc. ... The -o switch instructs gcc to place it's output in a file whose name is ...
    (comp.lang.c)
  • Re: Development / Debugging tools - advice needed.
    ... > command to make gdb show stuff in ... comparison to Linux as an OS. ... that the reason that Turbo Debugger ... control of the hardware away from it, ...
    (comp.os.linux.development.system)