[comp.lang.c] emptying stdin

chris@mimsy.umd.edu (Chris Torek) (05/09/90)

In article <826@kos.rci.dk> ofl@kos.rci.dk (Ole Frank Larsen) writes:
>Another short question: How do you empty the keyboard buffer without
>having to read all the keystrokes? I have tried fflush(stdin), but this
>does not work.

There is no standard way.  (The first part of the problem is being
sure that `stdin' and `keystrokes' mean the same thing.)  A few library
writers have tried the fflush(input_stream) idea.

The 4.4BSD stdio library has instead an `fpurge' call: fpurge(stream)
`erases' any pending input or output on the given stream.  This should
be used sparingly, if at all, and not only because it is not standard.
-- 
In-Real-Life: Chris Torek, Univ of MD Comp Sci Dept (+1 301 454 7163)
Domain:	chris@cs.umd.edu	Path:	uunet!mimsy!chris