Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!usc!snorkelwacker.mit.edu!bloom-picayune.mit.edu!news From: scs@adam.mit.edu (Steve Summit) Newsgroups: comp.lang.c Subject: Re: how do I clear stdin buffer Summary: how not to do it Message-ID: <1991Jun18.213328.7633@athena.mit.edu> Date: 18 Jun 91 21:33:28 GMT References: <43310@cup.portal.com> <2438@ccadfa.adfa.oz.au> Sender: news@athena.mit.edu (News system) Reply-To: scs@adam.mit.edu Organization: Thermal Technologies, Cambridge, MA Lines: 25 In article <2438@ccadfa.adfa.oz.au> bxw@ccadfa.adfa.oz.au (Brad Willcott) writes: > fflush (FILE *stream) > { > int i; > > while ((i = getc (stream)) != EOF) ; > } 1. One should not casually try (and ANSI prohibits) reimplementing routines with names reserved to the standard library, such as fflush. 2. When (illegally, but if you really know what you're doing) reimplementing standard routines, one should really attempt to preserve their existing semantics. (Consider what would happen if, elsewhere in the calling program, a call to fflush(stdout) were to encounter the reimplementation above.) 3. What the original problem statement required (not that it was really well defined or even portably possible) was a way to discard typed but unread data (presuming interactive input), not everything up to an EOF (i.e. the rest of the "file"). Steve Summit scs@adam.mit.edu