Skip to content Accesskey=4Skip to sub-navigation Accesskey=3View our Accessibility Options MIT Information Systems Home About IS&T Contact IS&T Site Map Search Advanced Search
Getting StartedGetting Services by Topic or Alphabetically Getting Help

On This Page

[Help]

  

Quick Links

Top Level

Related Links

Ask OLC a question

Athena Consulting Homepage

Helpdesk Stock Answers (for Mac/PC questions)


Controlling TERMINAL ECHO

To disable terminal echo in a C program, use the 'ioctl' (input/output
control) system function.  Here are examples of functions that disable 
and enable terminal echo, respectively:

For the Suns and SGIs (SVR4-based operating systems), you should use:

	#include <sys/ioctl.h>
	#include <termio.h>

	int main(int argc, char **argv)
	{
	  struct termio tty, oldtty;

	  /**
	   ** Save the old tty settings, and get rid of echo
	   ** for the new tty settings
	   **/
	  ioctl(0, TCGETA, &oldtty);
	  tty = oldtty;
	  tty.c_lflag    &= ~(ICANON|ECHO|ECHOE|ECHOK|ECHONL);
	  tty.c_cc[VMIN]  = 1;
	  tty.c_cc[VTIME] = 0;
	  ioctl(0, TCSETA, &tty);

	  /**
	   ** Now do whatever stuff you want non-echoed
	   **/


          /**
	   ** Now reset the old settings
	   **/
	  ioctl(0, TCSETA, &oldtty);
	}

For BSD-based operating systems, you would use the below snippet
of code.

For the DECstations, you can use either the above or the below:

	#include <sys/ioctl.h>
	#include <sgtty.h>

	int main(int argc, char **argv)
	{
	  struct sgttyb tty, oldtty;

	  /**
	   ** Save the old tty settings, and get rid of echo
	   ** for the new tty settings
	   **/
	  ioctl(0, TIOCGETP, &oldtty);
	  tty = oldtty;
	  tty.sg_flags |= CBREAK;
	  tty.sg_flags &= ~ECHO;
	  ioctl(0, TIOCSETN, &tty);

	  /**
	   ** Now do whatever stuff you want non-echoed
	   **/


          /**
	   ** Now reset the old settings
	   **/
	  ioctl(0, TIOCSETN, &oldtty);
	}

If you are interested in learning more about the 'ioctl' function, you can
read the manual page by using the 'man' command:

	man ioctl

Also, you may want to look at:

	man termio


Last modified:  Mar 9, 1996

MIT Home | Getting Started | Getting Services | Getting Help | About IS&T | Accessibility
Ask a technology question or send a comment about this web page.