Re: Problem Debugging C Program



John Hanley said:

<500+ lines of source code>

That's better.

Okay, you seem to have mixed up argc and argv somewhat, although the
effect is only to make the program harder to read, not actually wrong.

In the fprintf in main, replace infile with argc[1] (which we would
normally call argv[1], by the way!).

You shouldn't be passing argc[1] to fopen without first checking that
argv is at least 2.

fopen can fail, returning NULL - check for this.
fgets can fail, returning NULL - check for this.

Any one of these could have caused a segfault. If they don't, I'm sure
there's plenty more scope.

--
Richard Heathfield <http://www.cpax.org.uk>
Email: -www. +rjh@
Google users: <http://www.cpax.org.uk/prg/writings/googly.php>
"Usenet is a strange place" - dmr 29 July 1999
.



Relevant Pages

  • SOLVED: need to call managed code from unmanaged c++ code !
    ... Public Function(ByVal argc as Int32, ... SizeParamIndex:=0)> ByVal argvas string) as Int32 ... I tried the "Public Function(ByVal argc as Int32, ByVal/byRef argv as ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Understanding char **argv
    ... char **argv looks like. ... So as to dereference what the pointer that *argv pointed to. ... but modifying argv while leaving argc alone is odd. ...
    (comp.lang.c)
  • Re: passing more than one file.
    ... loop through argv[] until you hit NULL. ... message to stderr and keep going. ... int main(int argc, char *argv) { ...
    (comp.lang.c)
  • Re: Code Review - is this code shit
    ... main (int) can be invoked. ... The rules for C90 are simple: in a hosted implementation, ... int main(int argc, char **argv) ... is fed 1, 2, 3 respectively below, and I guess the value to argv ...
    (comp.lang.c)
  • Re: how to fake argv?
    ... i already know what the parameters mean (argc number of params and argv ... Another way of saying it is it's a pointer to an array of pointers. ...
    (comp.lang.c)