Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!cs.utexas.edu!uunet!virtech!cpcahil From: cpcahil@virtech.UUCP (Conor P. Cahill) Newsgroups: comp.lang.c Subject: Re: TO C OR NOT TO *C Message-ID: <1294@virtech.UUCP> Date: 20 Oct 89 20:40:49 GMT References: <16107@nswitgould.cs.uts.oz> <1989Oct16.172249.18387@utzoo.uucp> <991@cirrusl.UUCP> Organization: Virtual Technologies Inc Lines: 30 In article <991@cirrusl.UUCP>, dhesi%cirrusl@oliveb.ATC.olivetti.com (Rahul Dhesi) writes: > Playing Devil's advocate, we bravely yet blithely break Henry Spencer's > every rule: > char c; > c = getc(stdin); /* Oops! forgot to test for EOF! */ > do { > if feof(stdin) > break; /* WHEW! */ > .. do stuff with c .. > c = getc(stdin); > } while (1); And the same code could have been done without the break, without the overhead of the feof() function call for every iteration of the loop and (in my humble opinion) more readable as follows: int c; while( (c=getc(stdin)) != EOF); { .. do stuff with c .. } -- +-----------------------------------------------------------------------+ | Conor P. Cahill uunet!virtech!cpcahil 703-430-9247 ! | Virtual Technologies Inc., P. O. Box 876, Sterling, VA 22170 | +-----------------------------------------------------------------------+