ReadKey like Function in C

Doug Gwyn gwyn at smoke.BRL.MIL
Sun Aug 13 10:03:01 AEST 1989


In article <3727 at buengc.BU.EDU> bph at buengc.bu.edu (Blair P. Houghton) writes:
-In article <10712 at smoke.BRL.MIL> gwyn at brl.arpa (Doug Gwyn) writes:
->The Standard must accommodate a variety of environments.
-I don't get it.
-All it's gotta say is something to the effect that there should
-be a function, call it "readkey()", that returns the value of
-the next char from stdin as soon after it's typed as it's needed.
-You could even qualify it to apply only when tty input can be
-used as stdin.

We already have such a function in the Standard; it's called "getchar()".
It returns a single character from stdin as soon as it's available.
Whether or not there is input-line canonicalization going on is a matter
that depends on the operating environment.  Some systems always canonicalize,
some never do, and some can be made to switch from one mode to the other,
sometimes with side-effects like losing all unconsumed input and sometimes
not.  Some implementations cannot readily distinguish between "terminals"
and other I/O sources/sinks. This is the "variety of environments" alluded
to.  Any fully portable standard for this wide a range of behavior would
probably be so weak as to not meet the requirements of those who keep
asking for such a facility.  In fact there are are means of obtaining
uncanonicalized terminal input on most systems, and as I pointed out before
IEEE Std 1003.1 standardizes one such method for a wide class of systems
(POSIX-compliant ones).  I don't know (or much care) whether MS/DOS has
any such standard, but certainly one could be developed by those who care.



More information about the Comp.std.c mailing list