Newsgroups: comp.lang.c
Path: utzoo!utgpu!jarvis.csri.toronto.edu!dgp.toronto.edu!flaps
From: flaps@dgp.toronto.edu (Alan J Rosenthal)
Subject: Re: gotos
Message-ID: <8804241951.AA19166@champlain.dgp.toronto.edu>
Organization: University of Toronto
References: <2200@louie.udel.EDU> <1464@hubcap.UUCP>
Date:	Sun, 24 Apr 88 14:31:15 EDT


In article <1464@hubcap.UUCP> hutch@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

