[LCP]Unbuffered getchar()
McDonald, Joshua J (Josh)
joshmcdonald at lucent.com
Mon Apr 14 08:04:02 UTC 2003
Thanks for that guys.
And for anyone who's not able to follow the man pages on that stuff (Pretty
difficult if you're a newbie), note the following "ioctl(0, TCSETS, &ts);"
at the end of the following example, which resets the state to how it was to
begin with:
#include <stdio.h>
#include <termios.h>
#include <sys/ioctl.h>
main()
{
struct termios ts;
struct termios new_ts;
ioctl(0, TCGETS, &ts);
new_ts = ts;
new_ts.c_lflag &= !ICANON;
new_ts.c_lflag &= !ECHO;
ioctl(0, TCSETS, &new_ts);
char c; \
c=getchar(); } Program here
printf("%c\n",c); /
ioctl(0, TCSETS, &ts);
}
Josh
-----Original Message-----
From: Greg Black [mailto:gjb at gbch.net]
Sent: Friday, 11 April 2003 2:07 PM
To: David Lloyd
Cc: linuxcprogramming at lists.linux.org.au
Subject: Re: [LCP]Unbuffered getchar()
On 2003-04-11, David Lloyd wrote:
> > It's not rocket science. Read the manual. Specifically, read
> > how to save the state before you muck about with it. Then
> > restore it before you quit.
>
> Actually, if you were writing a terminal program to control a rocket
> then it WOULD be rocket science ;-P
In this case, it might be better termed suicide ...
Greg
More information about the linuxCprogramming
mailing list