getch() and getche() in MSC 4.0
Frank Swarbrick
swarbric at tramp.Colorado.EDU
Tue Oct 25 05:55:12 AEST 1988
In article <397 at dcscg1.UUCP> cpp90221 at dcscg1.UUCP (Duane L. Rezac) writes:
>I'm not sure about Microsoft C, but with turbo C and C86 optimizing Compiler,
>the getch() and getche() read one character out of the buffer. I have run into
>the problem with these functions skipping inputs due to some information that
>was left in the buffer from a previous read. When the second calling of the
>function occurs, it reads the remaining data in the buffer, appearing to run
>right past the requested input. At times I have had to add an extra getche() or
>getch() in front of the one that is skipping the input in order to clear the
>buffer.
>
>(by the way, if anyone has a good method to insure that the keyboard buffer is
> empty, Please post it.)
To clear the keyboard buffer I just do
#define clrkbdbuf() while (kbhit()) getch()
(of what I mean is I write that define and then call it as clrkbdbuf();)
There're probably better ways, but this works fine for me.
Frank Swarbrick (and, yes, the net.cat) University Of Colorado, Boulder
swarbric at tramp.Colorado.EDU ...!{ncar|nbires}!boulder!tramp!swarbric
"...don't believe in Goldman, his type like a curse
Instant Karma's gonna get him if I don't get him first" --U2
More information about the Comp.lang.c
mailing list