home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!haven.umd.edu!darwin.sura.net!zaphod.mps.ohio-state.edu!sample.eng.ohio-state.edu!purdue!mentor.cc.purdue.edu!sage.cc.purdue.edu!varney
- From: varney@sage.cc.purdue.edu (The Grand Master)
- Newsgroups: comp.unix.questions
- Subject: entering into cbreak mode with stty()
- Message-ID: <Bu9zHt.7LJ@mentor.cc.purdue.edu>
- Date: 8 Sep 92 19:58:41 GMT
- Sender: news@mentor.cc.purdue.edu (USENET News)
- Organization: Purdue University Computing Center
- Lines: 37
-
-
- I am trying to write a program that will allow you to input a
- value without having to hit return. I have tried the following, but it
- does not work correctly. It will not respond (no matter how many keys
- you hit) until you hit linefeed (return does nothing as well). At that
- point, the character is null, and my screen is then set to no echo, and
- no nl-cr translation.
- Could someone tell me what the problem is?
- Bruce
-
- --begin program--
- #include <stdio.h>
- #include <fcntl.h>
- #include <signal.h>
- #include <sgtty.h>
- main ()
- {
- register int fd, sig, n;
- char h;
- struct sgttyb sav_tty, chg_tty;
- if ((fd = open("/dev/tty", O_RDONLY))== -1)
- exit(1);
- if (gtty(0, &sav_tty))
- exit(2);
- chg_tty = sav_tty;
- chg_tty.sg_flags &= CBREAK;
- if (stty(0, &chg_tty))
- exit(3);
- printf("Hey, input a character : ");
- getchar(h);
- printf("\nThe character you input was %c.\n",h);
- chg_tty.sg_flags &= ~CBREAK;
- if (stty(0, &chg_tty))
- exit(3);
- close(fd);
- }
- --end program--
-