Another method of flushing the BIOS buffer is to call the console I/O function getch() until the function kbhit() becomes false. This method is demonstrated in the program below and has the advantage of being usable under OS/2 as well as MS-DOS.
The following sample program is an example:
/* Compile options needed: none
void main (void)
time_t start, work ;
char str  ;
puts ("type for getchar(). Go to stdin's buffer.") ;
// user can type more than one character and an Enter.
getchar () ;
puts ("Type fast, 5 seconds. Go to BIOS buffer.") ;
// user can type anything including multiple Enters.
time (&start) ;
work = start ;
while ( (work - start) < 5 ) time (&work) ;
bdos (0xC, 0, 0) ; // clear BIOS keyboard buffer
// Alternative method:
// while (kbhit()) getch();
fflush (stdin) ; // clear stdin's buffer
puts ("Should be waiting again.") ;
gets (str) ;
puts (str) ;
文書番号:43993 - 最終更新日: 2003/12/01 - リビジョン: 1