Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!ucsd!dog.ee.lbl.gov!elf.ee.lbl.gov!torek From: torek@elf.ee.lbl.gov (Chris Torek) Newsgroups: comp.lang.c Subject: Re: flushing input buffer Keywords: input, flushing, portable, fgets Message-ID: <12567@dog.ee.lbl.gov> Date: 27 Apr 91 13:45:09 GMT References: <1991Apr26.152944.1928@fys.ruu.nl> Reply-To: torek@elf.ee.lbl.gov (Chris Torek) Organization: Lawrence Berkeley Laboratory, Berkeley Lines: 28 X-Local-Date: Sat, 27 Apr 91 06:45:09 PDT In article <1991Apr26.152944.1928@fys.ruu.nl> boogaard@fys.ruu.nl (Martin vdBoogaard) writes: >Some of my programs use gets to read lines from stdin. (Switch to fgets. We deliberately made the gets() function obnoxious in the new BSD stdio. For those without time or inclination to fix their code, a quiet version of gets() appears in -lcompat.) >When [an] 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. Correct. >Does anyone have a portable clue? There is no portable input flush routine. The new BSD stdio has an `fpurge' function which `forgets' any pending input or output in a stdio stream. If the input is pending but not in a stream, however, you must use system-specific code (ioctl(TIOCFLUSH), e.g.). -- In-Real-Life: Chris Torek, Lawrence Berkeley Lab CSE/EE (+1 415 486 5427) Berkeley, CA Domain: torek@ee.lbl.gov