Single char input using getchar()
Guy Harris
guy at rlgvax.UUCP
Sat Dec 31 17:53:40 AEST 1983
There's nothing wrong with using getchar for single character
input. The stdio package treats terminals differently than it
does other devices. Terminal I/O will not be buffered by getchar
or putchar or any other stdio routine unless you request buffering
with setbuf(). The only buffering you have to worry about is
that controlled by ioctl.
Correction: terminals are treated differently by stdio only on output
(and, at least on 4.1cBSD, only on standard output, not on other streams;
I believe this is true of most stdio). Stdio will do a "read" system call
asking for a bufferful; however, the buffering shouldn't matter because a "read"
system call on a terminal in "CBREAK" mode will return as soon as any
input is available. In "~ICANON" mode (under the USG driver) the number of
characters that must be received before the wakeup occurs can be tuned.
Guy Harris
{seismo,ihnp4,allegra}!rlgvax!guy
More information about the Comp.lang.c
mailing list