Path: utzoo!attcan!uunet!husc6!cmcl2!adm!smoke!gwyn From: gwyn@smoke.BRL.MIL (Doug Gwyn ) Newsgroups: comp.lang.c Subject: Re: Always use braces Message-ID: <9235@smoke.BRL.MIL> Date: 27 Dec 88 05:46:51 GMT References: <5@rsoft.UUCP> <1071@goofy.megatest.UUCP> <861@quintus.UUCP> <271@twwells.uucp> <11037@ulysses.homer.nj.att.com> Reply-To: gwyn@brl.arpa (Doug Gwyn (VLD/VMB) ) Organization: Ballistic Research Lab (BRL), APG, MD. Lines: 37 In article <11037@ulysses.homer.nj.att.com> cjc@ulysses.homer.nj.att.com (Chris Calabrese[mav]) writes: >In article <271@twwells.uucp>, bill@twwells.uucp (T. William Wells) writes: >> In article <8@estinc.UUCP> fnf@estinc.UUCP (Fred Fish) writes: >> : ... They were teaching her to write code like: >> : inchar = getchar (); >> : while (inchar != EOF) >> : if (inchar == 0) >> : goto done; >> : else >> : inchar = getchar (); >> : done: return inchar; >Any C guru qualified (in my humble opinion) to teach >C would be trying to teach code which looks like: > do { > inchar = getchar(); > } while(inchar != EOF && inchar); > return inchar; Here's mine. The exact formatting is NOT IMPORTANT. What DOES matter is the comments and the fact that it is obvious how one gets each possible return value. #include #define MAGIC '\0' /* silly terminating character value */ int /* returns EOF or MAGIC (why??) */ some_function( void ) /* ANSI C assumed; else delete "void" */ { int c; /* character from standard input */ while ( (c = getchar()) != EOF ) if ( c == MAGIC ) return MAGIC; return EOF; }