Path: utzoo!utgpu!water!watmath!clyde!att!osu-cis!tut.cis.ohio-state.edu!mailrus!ncar!boulder!tramp!swarbric From: swarbric@tramp.Colorado.EDU (Frank Swarbrick) Newsgroups: comp.lang.c Subject: Re: getch() and getche() in MSC 4.0 Message-ID: <4258@boulder.Colorado.EDU> Date: 24 Oct 88 19:55:12 GMT References: <10508@dartvax.Dartmouth.EDU> <397@dcscg1.UUCP> Sender: news@boulder.Colorado.EDU Reply-To: swarbric@tramp.Colorado.EDU (Frank Swarbrick) Organization: Beautiful Boulder By The Bay Lines: 25 In article <397@dcscg1.UUCP> cpp90221@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@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