Article View: comp.os.msdos.programmer
Article #294Re: How to flush keyboard buffer?
From: David Anderson
Date: Fri, 07 Aug 1992 13:30
Date: Fri, 07 Aug 1992 13:30
39 lines
1792 bytes
1792 bytes
In article <DAVIS.92Aug6120347@pacific.mps.ohio-state.edu> davis@pacific.mps.ohio-state.edu (John E. Davis) writes: >In article <l82ffaINNc9j@utkcs2.cs.utk.edu> tackett@cs.utk.edu (Jack Tackett) writes: > >try fflush(stdin); > > >I am skeptical about this solution. Instead try something like: > > while(bioskey(1)) if (!getch()) getch(); > > Jack is correct to be skeptical about fflush(stdin)! It is NOT advisable to use the fflush() function with input streams such as stdin. WHY?? According to the ANSI standard, fflush() is only guaranteed to work on OUTPUT streams and *not* input streams. To do so on input streams is what is known in standards terms as "undefined behavior". What this means is that fflush() is guaranteed to work on output streams but if you use it on input streams, you can't rely on it working the same for every compiler! Many compilers allow the fflush to work with stdin, but it really isn't the place to do it :-) So what to do?? There are many ways, the simplist being that you must read all characters until it is empty. Regards, /David -- ------------------------------------------------------- David AR Anderson Email: anderson@Software.Mitel.COM Software Tools and Integration Mitel Corporation Disclaimer: My opinions are my own!
Technical Details
Message-ID:
<12537@anderson>Path:
arc1-ca.pugleaf.net!sparky!uunet!utcsri!torn!cunews!revcan!software.mitel.com!andersonReferences:
<3721@keele.keele.ac.uk> <l82ffaINNc9j@utkcs2.cs.utk.edu> <DAVIS.92Aug6120347@pacific.mps.ohio-state.edu>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!sparky!uunet!utcsri!torn!cunews!revcan!software.mitel.com!anderson From: anderson@Software.Mitel.COM (David Anderson) Newsgroups: comp.os.msdos.programmer Subject: Re: How to flush keyboard buffer? Message-ID: <12537@anderson> Date: 7 Aug 92 13:30:00 GMT References: <3721@keele.keele.ac.uk> <l82ffaINNc9j@utkcs2.cs.utk.edu> <DAVIS.92Aug6120347@pacific.mps.ohio-state.edu> Organization: Mitel. Kanata (Ontario). Canada. Lines: 39