emptying stdin (was sleep() in MSC 5.1 ???)

Chris Torek chris at mimsy.umd.edu
Wed May 9 14:04:37 AEST 1990


In article <826 at kos.rci.dk> ofl at 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 at cs.umd.edu	Path:	uunet!mimsy!chris



More information about the Comp.lang.c mailing list