[prog] C problem I am unable to solve

Colleen Hatfield evilpig at gmail.com
Fri May 13 01:53:49 EST 2005


On 5/12/05, Dan <dan at cellectivity.com> wrote:
> > The problem I have now is an infinate loop once it reaches the end of
> > the file.
> 
> I think the problem is here:
> 
> >      while ( (c = getc(inputfile)) != '\n' )
> >         putc(c, stdout); /* display the line */
> 
> EOF is not '\n'     :-)

That's just her inner loop to print the lines from the file.

I'd say the problem is that  "c" is declared as a char, but should be
an int since EOF is an int (-1).

- Colleen


More information about the Programming mailing list