how do I clear stdin buffer

Taos Mountain Software tms at cup.portal.com
Sat Jun 15 04:45:32 AEST 1991


The stdio function "scanf" works great for input from datafiles, but I always
run into problems when doing interactive tty I/O on Unix systems.

For example, this simple program will go into an infinite loop
if the entry is a non-digit for example ("abc").

	main ()
	{
		int x,stat;;
		do {
			stat=scanf("%d",&x);
		} while (stat != 1);
		...
		...
	}
I know there are plenty of workarounds, but what I'm interested in is a
function like fflush that deals with input streams.

Thanks in advance

Ric Urrutia
tms at cup.portal.com



More information about the Comp.lang.c mailing list