Click to See Complete Forum and Search --> : Stupid linux specific C question...flushall?


StarWeaver
12-07-2000, 09:22 PM
My C instructor told us to use flushall() to clear the input buffer and prevent scanf from causeing an infinate loop if it gets the wrong input etc. Of course this works fine on the 2k systems at school, but my stdio.h for gcc/glib dosen't HAVE a flushall() (AFAIK) ... what's another way of doing this? The info only seems to indicate flushing of output streams...

Thanks
-Ronin Angel StarWeaver

Strike
12-07-2000, 11:23 PM
just fflush(NULL); flushes all open output streams

(in stdio.h)

StarWeaver
12-09-2000, 02:19 AM
But... i need to flush input streams, not output. I found a fclean() function in the GNU docs (in the low level output section, someting like 'working with llio + streams' sectoin.) Problem is, it does not say what header it's in, and i've grepped /usr/include for it and nothing.

Oh well, i just made function like this:

int inputstuff( long * input )
{
int inp_ok;
long inp_tmp;
int inp_buffer[100];

fgets( &buffer, 100, stdin );
sscanf( &buffer, "%ld", &inp_tmp );
*input = inp_tmp;

...if scanf matched, return TRUE, else FALSE (for idiot checking)...
}


Works for me :)