1-char input in C - (nf)
franka at tekcad.UUCP
franka at tekcad.UUCP
Mon Dec 26 04:10:47 AEST 1983
#R:ihuxn:-46300:tekcad:2600002:000:1170
tekcad!franka Dec 25 10:10:00 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
The other problem with this is that if somebody hits a ^C (or ^\)
during the getchar, the terminal gets put in "raw" mode. This is very, very
confusing to a novice user (I assume that is who you are writing for, with
such a limited command set) who suddenly cannot backspace, use the return
key on a command, etc.
From the truly menacing,
/- -\ but usually underestimated
<-> and soon to be gone,
Frank Adrian
(tektronix!tekcad!franka)
More information about the Comp.lang.c
mailing list