1-char input in C

John Nelson john at genrad.UUCP
Fri Dec 23 07:55:41 AEST 1983


Your problem is a common one.  The problem is that UNIX is buffering up
the data, as opposed to the C library routines.  The most portable solution
(and easiest to understand) is to use the system() call to change the
tty mode as follows:

#include <stdio.h>
main() {
    system("stty raw");		/* dont buffer data */
    getchar();
    system("stty -raw");	/* restore normal buffering */
}

The other option is to use ioctl() (or gtty & stty on systems that have it)
to set the tty modes properly.  The problem with this is that BELL, BSD and
V7 systems are all different in the exact format of these ioctl()'s



More information about the Comp.lang.c mailing list