[prog] C++ - linked list and segmentation fault

Jenn Vesperman jenn at anthill.echidna.id.au
Wed Apr 9 03:32:09 EST 2003


On Wed, 2003-04-09 at 03:10, Jennifer Davis wrote:
> 
> I was wondering if I could get some advice on a program I am trying to
> complete for class.  It is a killer as I am new to linked lists.  I write
> the program and it compiles.  However, when it runs, it segfaults.  I'm
> sure it happens when I am creating the list.  All help would be very much
> appreciated.

I'll start with a technique.

Every so often in any program, put:

#ifdef DEBUG
  (output that says 'we got to this point')
  (possibly output that lists what values variables have)
#endif

Then in the start of your program:

#define DEBUG 1
or
#define DEBUG 0

depending on whether you're debugging or not. :)

This will tell you which part of the code is failing, rather than you
having to guess.


 
> #include<iostream.h> // for cin & cout
> #include<stdio.h>    // for I don't know what
> #include<stdlib.h>   // for I don't know what

Find out. :)




Jenn V.
-- 
    "Do you ever wonder if there's a whole section of geek culture 
        	you miss out on by being a geek?" - Dancer.
 My book 'Essential CVS' will be published by O'Reilly in 2003.
jenn at anthill.echidna.id.au     http://anthill.echidna.id.au/~jenn/




More information about the Programming mailing list