TO C OR NOT TO *C

Conor P. Cahill cpcahil at virtech.UUCP
Sat Oct 21 06:40:49 AEST 1989


In article <991 at cirrusl.UUCP>, dhesi%cirrusl at 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     |
+-----------------------------------------------------------------------+



More information about the Comp.lang.c mailing list