getch() and getche() in MSC 4.0
Gordon Smith
gsmith at umd5.umd.edu
Mon Oct 24 11:56:30 AEST 1988
In article <10508 at dartvax.Dartmouth.EDU> jalphin at prism.clemson.edu writes:
>
> [This article was written by Scott Horne, not Yaping Xu.
>
>Has anyone else had trouble with getch() and getche() in Microsoft C v. 4.0?
>They often skip every other keypress on me--and in one case, they skip two
>keypresses out of three! Maybe it's my code. This occurs mainly when I try
>
> c = toupper(getch());
>
The reason your program is not working correctly, is because of
the toupper, not the getch. toupper() is implemented as a macro, not a
function. Therefore the code MAY look similiar to this:
c = isalpha(getch()) && isupper(getch()) ? getch() : getch()-'a'+'A';
Therefore executing getch() more than once. This may not be the exact
macro description for toupper, but it does illustrate the point.
More information about the Comp.lang.c
mailing list