home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / lang / c / 19257 < prev    next >
Encoding:
Text File  |  1993-01-05  |  1.9 KB  |  67 lines

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!math.fu-berlin.de!news.th-darmstadt.de!rbg.informatik.th-darmstadt.de!misar
  3. From: misar@rbg.informatik.th-darmstadt.de (Walter Misar)
  4. Subject: Re: How to read without echo.
  5. Sender: news@news.th-darmstadt.de (The News System)
  6. Message-ID: <1993Jan5.172545@rbg.informatik.th-darmstadt.de>
  7. Date: Tue, 5 Jan 1993 16:25:45 GMT
  8. References:  <1i9pi5INN972@taloa.unice.fr> <1993Jan4.182945@rbg.informatik.th-darmstadt.de>
  9. Nntp-Posting-Host: rbhp87.rbg.informatik.th-darmstadt.de
  10. Organization: TH Darmstadt
  11. Lines: 54
  12.  
  13. In article <1993Jan4.182945@rbg.informatik.th-darmstadt.de>, misar@rbg.informatik.th-darmstadt.de (walter misar) writes:
  14. > #include <sgtty.h>
  15. > main()
  16. > { struct sgttyb *ttyio;
  17. >   ...
  18. >   gtty(0,ttyio);
  19. >   (ttyio->sg_flags)&=(~ECHO);    /* echo off    */
  20. >   stty(0,ttyio);   
  21. >   ...   /* read without echo */
  22. >   (ttyio->sg_flags)|=(ECHO);    /* echo on    */
  23. >   stty(0,ttyio);
  24. >   .....
  25. > }
  26.  
  27. Oops, there was an error (the pointer of ttyio never gets initialized).
  28. Strange enough, it worked for me.
  29. This could be fixed as follows:
  30.  
  31. #include <sgtty.h>
  32. main()
  33. { struct sgttyb ttyio;
  34.  ...
  35.  gtty(0,&ttyio);
  36.  (ttyio.sg_flags)&=(~ECHO);    /* echo off    */
  37.  stty(0,&ttyio);   
  38.  ...   /* read without echo */
  39.  (ttyio.sg_flags)|=(ECHO);    /* echo on    */
  40.  stty(0,&ttyio);
  41.  .....
  42. }  
  43.  
  44. However a more portable way would be to use ioctl:
  45.  
  46. #include <sys/ioctl.h>
  47. #include <termio.h>
  48. /* Hm, my manpage says to use termios instead, but that didn't work (HPUX8.0) */
  49.  
  50. main()
  51. { struct termio ttyio;
  52.  
  53.   ioctl(0,TCGETA,&ttyio);
  54.   ttyio.c_lflag &= ~ECHO;
  55.   ioctl(0,TCSETA,&ttyio);
  56.    ... /* read without echo */
  57.   ttyio.c_lflag |= ECHO;
  58.   ioctl(0,TCSETA,&ttyio);
  59.   ...
  60. }
  61.  
  62. Thanks to the people, who told me about the error.
  63.  
  64. -- 
  65. Walter Misar                        It is impossible to enjoy idling thoroughly
  66. misar@rbg.informatik.th-darmstadt.de       unless one has plenty of work to do.
  67.