I\'m working on a program which will be taking in user input from the console as well as printfing out in a separate thread. I want to avoid situations where the user is hal
Here's an example of how to turn off echo from C, taken directly from an HP forum (and I haven't personally tested it):
Okay this should be a simple example of turning off echo:
#include
#include #include #include #define STDIN_FDES 0 struct termios save; int main(int argc, char *argv[]) { int cc = 0; char s_tmp[80],*p = NULL; struct termios work; cc = tcgetattr(STDIN_FDES,&save); work = save; work.c_lflag &= ~(ECHO); cc = tcsetattr(STDIN_FDES,TCSANOW,&work); (void) printf("\nEnter value: "); (void) fflush(stdout); p = fgets(s_tmp,sizeof(s_tmp),stdin); if (p != NULL) (void) printf("Out -> %s\n",p); cc = tcsetattr(STDIN_FDES,TCSANOW,&save); return(cc); } NOTE: It is very important that you have signal handlers to catch SIGINT, SIGTERM, ... and reset the terminal using the original termios because the last tcsetattr() wins and this applies to the terminal device NOT simply the process. If you leave the process with echo off, it will be off in the shell as well.
Otherwise, if Bash is a suitable approach, apparently you can just do stty -echo.