home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c
- 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
- From: misar@rbg.informatik.th-darmstadt.de (walter misar)
- Subject: Re: How to read without echo.
- Sender: news@news.th-darmstadt.de (The News System)
- Message-ID: <1993Jan4.182945@rbg.informatik.th-darmstadt.de>
- Date: Mon, 4 Jan 1993 17:29:45 GMT
- References: <1i9pi5INN972@taloa.unice.fr>
- Nntp-Posting-Host: rbhp60.rbg.informatik.th-darmstadt.de
- Organization: TH Darmstadt
- Lines: 46
-
- In article <1i9pi5INN972@taloa.unice.fr>, vyskocil@taloa.unice.fr (Vyskocyl) writes:
- > Hi!
- > I got a little question, which will certainly be just a
- > piece of cake for such talentuous programmers as you are.
- >
- > I only want to read a word on the keyboard without any
- > print on the screen. I mean, I want someone to answer
- > a question on his keyboard without any echo of what he
- > is typing. It will end just after he pressed 'return'.
- > ex: do a little program which does perform this :
- >
- > What's the color of a pumpkin ? :
- > (now the guy type something but it doesn't appear on
- > his screen!)
- > then :
- > True! or False! whether the answer is light-blue or
- > not 8-) .
-
- Why do you guys never mention the OS you use ? (sigh)
-
- Ok, let's assume U use Unix:
- If the answer were only up to 8 bytes long, you could have
- used getpass():
- #include <unistd.h>
- ...
- answerstring=getpass("What's the color of a pumpkin ?");
- ....
-
- But since the answer is longer, you have to use something like this:
-
- #include <sgtty.h>
- main()
- { struct sgttyb *ttyio;
- ...
- gtty(0,ttyio);
- (ttyio->sg_flags)&=(~ECHO); /* echo off */
- stty(0,ttyio);
- ... /* read without echo */
- (ttyio->sg_flags)|=(ECHO); /* echo on */
- stty(0,ttyio);
- .....
- }
-
- --
- Walter Misar It is impossible to enjoy idling thoroughly
- misar@rbg.informatik.th-darmstadt.de unless one has plenty of work to do.
-