home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / unix / question / 10832 < prev    next >
Encoding:
Text File  |  1992-09-08  |  1.4 KB  |  48 lines

  1. 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
  2. From: varney@sage.cc.purdue.edu (The Grand Master)
  3. Newsgroups: comp.unix.questions
  4. Subject: entering into cbreak mode with stty()
  5. Message-ID: <Bu9zHt.7LJ@mentor.cc.purdue.edu>
  6. Date: 8 Sep 92 19:58:41 GMT
  7. Sender: news@mentor.cc.purdue.edu (USENET News)
  8. Organization: Purdue University Computing Center
  9. Lines: 37
  10.  
  11.  
  12.     I am trying to write a program that will allow you to input a 
  13. value without having to hit return. I have tried the following, but it
  14. does not work correctly. It will not respond (no matter how many keys
  15. you hit) until you hit linefeed (return does nothing as well). At that
  16. point, the character is null, and my screen is then set to no echo, and
  17. no nl-cr translation.
  18.     Could someone tell me what the problem is?
  19.             Bruce
  20.  
  21. --begin program--
  22. #include <stdio.h>
  23. #include <fcntl.h>
  24. #include <signal.h>
  25. #include <sgtty.h>
  26. main ()
  27. {
  28. register int fd, sig, n;
  29. char h;
  30. struct sgttyb sav_tty, chg_tty;
  31. if ((fd = open("/dev/tty", O_RDONLY))== -1)
  32.     exit(1);
  33. if (gtty(0, &sav_tty))
  34.     exit(2);
  35. chg_tty = sav_tty;
  36. chg_tty.sg_flags &= CBREAK;
  37. if (stty(0, &chg_tty))
  38.     exit(3);
  39. printf("Hey, input a character : ");
  40. getchar(h);
  41. printf("\nThe character you input was %c.\n",h);
  42. chg_tty.sg_flags &= ~CBREAK;
  43. if (stty(0, &chg_tty))
  44.     exit(3);
  45. close(fd);
  46. }
  47. --end program--
  48.