gotos

Alan J Rosenthal flaps at dgp.toronto.edu
Mon Apr 25 04:31:15 AEST 1988


In article <1464 at hubcap.UUCP> hutch at hubcap.UUCP (David Hutchens) writes:
>Indeed, in my implementation I may call keypressed a second
>time after I've already received a true response.  This could be
>fixed easily enough with another local variable, but that would just
>make it harder to understand.

Better yet, if keypressed() is considered part of the i/o library, it
could keep its own local flag, if the following two changes were made:

-> When keypressed() is called, if the flag is set, just return true;
   else actually look for a keypress and if there is one then set the
   flag and return true.

-> All other input functions clear the flag if they do actual input.
   As an optimization, perhaps ungetc() sets the flag (scanf() too if
   applicable).

In fact, keypressed() probably already works like this.  If not, you
can certainly wrap your own routine around it, or write your
mykeypressed() routine that keeps a flag and does the low-level gunge
itself.

ajr




More information about the Comp.lang.c mailing list