Re: Problem Debugging C Program
- From: Richard Heathfield <rjh@xxxxxxxxxxxxxxx>
- Date: Tue, 28 Aug 2007 20:49:30 +0000
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
.
- References:
- Problem Debugging C Program
- From: John Hanley
- Re: Problem Debugging C Program
- From: Willem
- Re: Problem Debugging C Program
- From: John Hanley
- Re: Problem Debugging C Program
- From: Willem
- Re: Problem Debugging C Program
- From: John Hanley
- Problem Debugging C Program
- Prev by Date: Re: Problem Debugging C Program
- Next by Date: Re: efficient comparison
- Previous by thread: Re: Problem Debugging C Program
- Next by thread: Re: Problem Debugging C Program
- Index(es):
Relevant Pages
|