www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1995/05/12/10:41:27

From: "A.Appleyard" <A DOT APPLEYARD AT fs2 DOT mt DOT umist DOT ac DOT uk>
To: DJGPP AT SUN DOT SOE DOT CLARKSON DOT EDU
Date: Fri, 12 May 1995 14:28:29 BST
Subject: flushing the keyboard buffer

  gilliard AT lectra DOT fr (Laurent Pierre Gilliard) asked:-
>How can i empty the keyboard buffer with gcc?

(1) tony AT nt DOT tuwien DOT ac DOT at (Anton Helm) replied:-
#include <pc.h>
while(kbhit()) getkey();
/* unfortunately this is not very portable... */

(2) pascal DOT richard AT art DOT alcatel DOT fr (Pascal RICHARD) replied:-
 You must use :
   fflush (stdin);

  I suspect that (1) flushes the PC's buffer, and (2) flushes djgpp's buffer.
These are two distinct buffers. scanf() etc read from buffer (2). When scanf()
etc find buffer (2) empty, they call _filbuf() to read from buffer (1) into
buffer (2). I think. Some functions such as getkey() read straight from buffer
(1), bypassing buffer (2).

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019