Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!wuarchive!gem.mps.ohio-state.edu!tut.cis.ohio-state.edu!bloom-beacon!eru!luth!sunic!mcsun!ukc!mucs!r6!ian From: ian@r6.uucp (Ian Cottam) Newsgroups: comp.lang.c Subject: Re: EOF considered harmful Message-ID: <294@m1.cs.man.ac.uk> Date: 24 Oct 89 11:13:38 GMT References: <266@m1.cs.man.ac.uk> Sender: news@cs.man.ac.uk Reply-To: ian@r6.UUCP (Ian Cottam) Organization: University of Manchester, UK Lines: 46 In article <266@m1.cs.man.ac.uk> ian@r6.UUCP I (Ian Cottam) write: >Some observations on the little program below (following some recent >discussions in this group): >_______________________ >#include > >int >main() >{ > char ch; > while ( ! feof(stdin) ) { > ch= getchar(); > putchar(ch); > } > > return 0; >} >______________________ Whoops! Red face! Is this any better (he says cautiously)? _______ #include int main() { char ch; for(;;) { ch= getchar(); if ( feof(stdin) || ferror(stdin) ) break; else putchar(ch); } return 0; } _________ ----------------------------------------------------------------- Ian Cottam, Room IT101, Department of Computer Science, University of Manchester, Oxford Road, Manchester, M13 9PL, U.K. Tel: (+44) 61-275 6157 FAX: (+44) 61-275-6280 Internet: ian%cs.man.ac.uk@nss.cs.ucl.ac.uk JANET: ian@uk.ac.man.cs UUCP: ..!mcvax!ukc!man.cs!ian -----------------------------------------------------------------