Path: utzoo!utgpu!jarvis.csri.toronto.edu!rutgers!ucsd!chem.ucsd.edu!tps From: tps@chem.ucsd.edu (Tom Stockfisch) Newsgroups: comp.lang.c Subject: Re: EOF considered harmful Message-ID: <584@chem.ucsd.EDU> Date: 24 Oct 89 00:50:07 GMT References: <266@m1.cs.man.ac.uk> Reply-To: tps@chem.ucsd.edu (Tom Stockfisch) Organization: Chemistry Dept, UC San Diego Lines: 20 In article <266@m1.cs.man.ac.uk> ian@r6.UUCP (Ian Cottam) writes: > char ch; > while ( ! feof(stdin) ) { > ch= getchar(); > putchar(ch); > } >1) This program runs as quickly as the ``((ch= getchar()) != EOF)'' > version (on my SUN3 with gcc). The problem with this version is that feof() does not test for an error condition on stdin, whereas getc() will return EOF on i/o error. So your program might loop infinitely if there is an i/o error. The above code fragment will also fill up the disk with (char)EOF if chars are unsigned. -- || Tom Stockfisch, UCSD Chemistry tps@chem.ucsd.edu