how do I clear stdin buffer

Steve Summit scs at adam.mit.edu
Wed Jun 19 07:33:28 AEST 1991


In article <2438 at ccadfa.adfa.oz.au> bxw at 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 at adam.mit.edu



More information about the Comp.lang.c mailing list