Simple question.

Richard A. O'Keefe ok at goanna.cs.rmit.oz.au
Fri May 3 16:25:22 AEST 1991


In article <24528 at well.sf.ca.us>, ron at well.sf.ca.us (Ronald Hayden) writes:
> cfiddyme at gara.une.oz.au (Kith Kanan) writes:
> > Could someone please tell me if it is possible to read a string with
> > scanf() and not have the string printed on the screen.
> >                          Thanks.
> >                                 Chris.

> scanf() will always echo the characters, but getchar() won't.  If
> you're receiving more than one character, though, you'll have to call
> getchar() multiple times, as it only processes a character at a time.

This is an operating-system-specific question.  On the machines I
normally use, the statement "scanf() will always echo the characters,
but getchar() won't" is simply false.  For example, when scanf() is
reading from a file, nothing is echoed.  More to the point, on UNIX
machines, whether echoing is done or not is part of the state of the
terminal driver, and has nothing to do with which stdio functions (if
any) you are using.

What you _really_ want to do is to find out about the "curses" package.
"curses" comes with UNIX, the "curses" interface is available in VAX/VMS
C, and there are several versions of "curses" for PCs, including a free
one.  Using curses:
	noecho();
	scanw(format, args...);
	echo();

-- 
Bad things happen periodically, and they're going to happen to somebody.
Why not you?					-- John Allen Paulos.



More information about the Comp.lang.c mailing list