Path: utzoo!mnetor!uunet!husc6!bbn!bbn.com!rsalz From: rsalz@bbn.com (Rich Salz) Newsgroups: comp.lang.c Subject: Re: C Quirk?? Message-ID: <413@fig.bbn.com> Date: 17 Feb 88 18:28:32 GMT References: <1653@ssc-vax.UUCP> <804@PT.CS.CMU.EDU> <23498@hi.unm.edu> <186@ateng.UUCP> <885@PT.CS.CMU.EDU> Organization: BBN Laboratories, Cambridge MA Lines: 24 =>>#define clearline() while (getchar() != '\n') => This is seriously bad code. What if stdin reaches end of file? = = It loops forever -- oops. Change that to =#define clearline() while (1) {int ch = getchar(); \ = if ((ch == EOF) || (ch =='\n')) break; } Not quite yet; the following "obvious" fragment won't compile (try it before posting "why" to the net): if (a) if (b) clearline(); else printf("Don't know about b, but a is zero.\n"); This should work: #define clearline() \ while (getchar() != '\n' && !feof(stdin) && !ferror(stdin)) As a general rule, you probably don't want to use { } in #define's as { }; is not the same as { }. /r$ -- For comp.sources.unix stuff, mail to sources@uunet.uu.net.