C Quirk??

Eddie Wyatt edw at IUS1.CS.CMU.EDU
Thu Feb 18 00:27:30 AEST 1988


> >
> >#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; }

 
-- 

Eddie Wyatt 				e-mail: edw at ius1.cs.cmu.edu



More information about the Comp.lang.c mailing list