Making chars disappear

uunet!bria!mike uunet!bria!mike
Mon Feb 18 12:48:55 AEST 1991


>In an article, castle.ed.ac.uk!james (J Gillespie) writes:
>Does anyone know of a way to prevent characters being echoed as they
>are typed in?  Like when you log in, your password doesn't get echoed.
>I have a nasty feeling this may involve sending control codes to the
>terminal.

To disable echo on your terminal from within a program (assuming that
you don't want to link in the curses library), and your system groks
termio, then you can use this chunk of code:

----- cut here -------------------------------------------------------------

#include <termio.h>

echo(state)
int state;
{
static int		setonce = 0;
static struct termio	old, new;

	if ( ! setonce ) {
		ioctl(0, TCGETA, &old);
		ioctl(0, TCGETA, &new);
		new.c_lflag &= ~ECHO;		/* turn echo bit off */
		setonce = 1;
		}

	if ( ! state )
		ioctl(0, TCSETA, &new);
	else
		ioctl(0, TCSETA, &old);
}

-----------------------------------------------------------------------------

Thus, to turn the echo off, use echo(0), and to turn it back on echo(1).
Hope this helps.

Cheers,
-- 
Michael Stefanik, MGI Inc., Los Angeles| Opinions stated are not even my own.
Title of the week: Systems Engineer    | UUCP: ...!uunet!bria!mike
-------------------------------------------------------------------------------
Remember folks: If you can't flame MS-DOS, then what _can_ you flame?



More information about the Comp.unix.programmer mailing list