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

  1. Newsgroups: comp.lang.c
  2. Path: sparky!uunet!munnari.oz.au!spool.mu.edu!yale.edu!ira.uka.de!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: <1993Jan4.182945@rbg.informatik.th-darmstadt.de>
  7. Date: Mon, 4 Jan 1993 17:29:45 GMT
  8. References:  <1i9pi5INN972@taloa.unice.fr>
  9. Nntp-Posting-Host: rbhp60.rbg.informatik.th-darmstadt.de
  10. Organization: TH Darmstadt
  11. Lines: 46
  12.  
  13. In article <1i9pi5INN972@taloa.unice.fr>, vyskocil@taloa.unice.fr (Vyskocyl) writes:
  14. > Hi!
  15. > I got a little question, which will certainly be just a 
  16. > piece of cake for such talentuous programmers as you are.
  17. > I only want to read a word on the keyboard without any
  18. > print on the screen. I mean, I want someone to answer
  19. > a question on his keyboard without any echo of what he
  20. > is typing. It will end just after he pressed 'return'.
  21. > ex: do a little program which does perform this :
  22. >  
  23. >  What's the color of a pumpkin ? :
  24. > (now the guy type something but it doesn't appear on
  25. > his screen!)
  26. >  then :
  27. >  True! or False! whether the answer is light-blue or
  28. > not 8-) .
  29.  
  30. Why do you guys never mention the OS you use ? (sigh)
  31.  
  32. Ok, let's assume U use Unix:
  33. If the answer were only up to 8 bytes long, you could have
  34. used getpass():
  35. #include <unistd.h>
  36. ...
  37. answerstring=getpass("What's the color of a pumpkin ?");
  38. ....
  39.  
  40. But since the answer is longer, you have to use something like this:
  41.  
  42. #include <sgtty.h>
  43. main()
  44. { struct sgttyb *ttyio;
  45.   ...
  46.   gtty(0,ttyio);
  47.   (ttyio->sg_flags)&=(~ECHO);    /* echo off    */
  48.   stty(0,ttyio);   
  49.   ...   /* read without echo */
  50.   (ttyio->sg_flags)|=(ECHO);    /* echo on    */
  51.   stty(0,ttyio);
  52.   .....
  53. }
  54.   
  55. -- 
  56. Walter Misar                        It is impossible to enjoy idling thoroughly
  57. misar@rbg.informatik.th-darmstadt.de       unless one has plenty of work to do.
  58.