1-char input in C - (nf)

grunwald at uiuccsb.UUCP grunwald at uiuccsb.UUCP
Fri Jan 13 13:28:55 AEST 1984


#R:ihuxn:-46300:uiuccsb:9000009:000:915
uiuccsb!grunwald    Jan 12 12:21:00 1984

re: using read over getchar to not buffer input

While it is true that when using the STDIO package, getchar and putchar cause
input to be buffered, the action that is occuring is due to the terminal
device driver. If one used "read" without changing to cbreak or raw mode, you
would still need to press return for the read to finish.
   When not using STDIO, getchar is equivilent to:

getchar()
{
	int	ch;
	read(STDIN,ch,1);
	return(ch);
}

When using STDIO, getchar is in fact a #define macro. When it runs out of
valid data in the current buffer, it calls "read" to fill up the buffer.

   If you're not doing a lot of mucking around, with switching between CBREAK,
RAW and COOKED modes, using the "system" call is sufficient. Otherwise, you
might want to look at ioctl(2) and tty(4) in the UNIX manual.

Dirk Grunwald
University of Illinois
USENET	: ihnp4 ! uiucdcs ! grunwald
CSNET	: grunwald.uiuc at Rand-Relay



More information about the Comp.lang.c mailing list