flushing input buffer

Martin vdBoogaard boogaard at fys.ruu.nl
Sat Apr 27 01:29:44 AEST 1991


Some of my programs use gets to read lines from stdin. Suppose that
(1) processing any of these lines takes a program some time and (2) the
user has already entered the second line of input when the program discovers
an error in the first line.

When this error is detected, the program skips the rest of the
offending input line (which is not likely to make much sense either).
In addition I'd like to be able to skip any input the user has already
entered up to the moment the program decides it must handle the error.
I can't use gets because I don't know *how much* superfluous input I have
to skip. The fflush function works only for *output* streams.

Does anyone have a portable clue?


Martin J. van den Boogaard                 |        boogaard at fys.ruu.nl
-----------------------------------------------------------------------
Dept. of Atomic & Interface Physics        |            the Netherlands
Debye Institute--Utrecht University        |        phone +31 30 532904
P.O. Box 80.000, NL-3508 TA Utrecht        |        fax   +31 30 543165
-----------------------------------------------------------------------
some days you wake up and immediately start to worry. nothing in
particular is wrong, it's just the suspicion that forces are aligning
quietly and there will be trouble.            --           Jenny Holzer
-----------------------------------------------------------------------



More information about the Comp.lang.c mailing list