[comp.lang.c] no echo?

bcf2303@dcrbg1.UUCP (Wing Chow) (01/20/88)

      can you tell me how to avoid 'echoing' back to the user what he/she
is typing in?

    thanks again for any help as i am new to unix and c.

gp@picuxa.UUCP (Greg Pasquariello X1190) (01/21/88)

In article <128@dcrbg1.UUCP>, bcf2303@dcrbg1.UUCP (Wing Chow) writes:
> 
> 
>       can you tell me how to avoid 'echoing' back to the user what he/she
> is typing in?
> 
>     thanks again for any help as i am new to unix and c.


You don't mention which machine or compiler you are using, but the standard
libraries for a few diffenent DOS C compilers contain the function getch().
This function will do exactly what you want it to do.  If your library does
not include getch(), you may be able to do it with the systems DOS interface
(i.e. bdos() or intdos()).

Unix Sys 5 has a library function called getpass() that will prompt the user
with a string (of your choosing), and get the typed response without echoing
the characters to the screen.

gwyn@brl-smoke.ARPA (Doug Gwyn ) (01/21/88)

In article <128@dcrbg1.UUCP> bcf2303@dcrbg1.UUCP (Wing Chow) writes:
>      can you tell me how to avoid 'echoing' back to the user what he/she
>is typing in?

The details of how to do this depend on the specific operating system
environment.  On UNIX, the simplest thing is
	system("stty -echo");
to disable echoing and
	system("stty echo");
to reenable it (important!).  For more direct control, you would have
to use an appropriate ioctl() call; see TTY(4) or TERMIO(7) in your UNIX
Programmer's Reference Manual (or Administrator Reference Manual) for
details of terminal-related ioctls.  The proposed IEEE Std 1003 specifies
some library functions to be used instead of ioctl() calls, but they are
probably not yet in your C library.

wswietse@eutrc3.UUCP (Wietse Venema) (01/22/88)

In article <128@dcrbg1.UUCP>, bcf2303@dcrbg1.UUCP (Wing Chow) writes:
> 
>       can you tell me how to avoid 'echoing' back to the user what he/she
> is typing in?
> 
>     thanks again for any help as i am new to unix and c.

Questions of this nature often show up in the news group comp.unix.questions.

Try system("stty -echo"); it should work on all unixes, tho it not
very efficiently. Try `man tty' for a more efficient implementation.

ok@quintus.UUCP (Richard A. O'Keefe) (01/25/88)

In article <173@eutrc3.UUCP>, wswietse@eutrc3.UUCP (Wietse Venema) writes:
> In article <128@dcrbg1.UUCP>, bcf2303@dcrbg1.UUCP (Wing Chow) writes:
> > can you tell me how to avoid 'echoing' back to the user what he/she
> > is typing in?
> Questions of this nature often show up in the news group comp.unix.questions.
> Try system("stty -echo"); it should work on all unixes, tho it not
> very efficiently. Try `man tty' for a more efficient implementation.

(1) If you want a method which works under other operating systems,
    find out about Curses.  The functions
	initscr();	/* Start Curses up */
	noecho();	/* Turn echoing off */

	echo();		/* Turn echoing on */
	endwin();	/* Shut Curses down */
    are the ones you want.  Curses is available under VMS, and there
    are several emulations of it around for IBM PCs (there was source
    code for one in Dr Dobbs last year).

(2) Whatever you do, DON'T forget to turn echoing back on again!
    system("stty echo") is the complement to system("stty -echo").
    The easiest way to manage this is to write yourself a function

	void my_exit(n)
	    int n;
	    {
		echo();		/* or whatever */
		endwin();	/* other shutting down */
		/* delete any scratch files you have open */
		exit(n);
	    }

	my_handler()
	    {
		my_exit(1);
	    }
		
	main()
	    {
		...				/* catch all the signals */
		signal(SIGQUIT, my_handler);	/* that terminate programs */
		...				/* and make them call your */
		signal(SIGTERM, my_handler);	/* graceful-exit routine */
		...
		initscr();
		...
	    }

    In any program which creates scratch files you should be doing
    something like this anyway.  It's a bit of a pain, but believe
    me, it's more of a pain to have someone explain your faults
    when a program of yours leaves their terminal in a strange
    state and they don't know how to get it back.