In Windows, you can turn off echo for any standard input function with SetConsoleMode().
Code:
#include <stdio.h>
#include <windows.h>
int main()
{
HANDLE hStdin = GetStdHandle(STD_INPUT_HANDLE);
DWORD mode = 0;
char buff[25];
GetConsoleMode(hStdin, &mode);
SetConsoleMode(hStdin, mode & (~ENABLE_ECHO_INPUT));
fgets(buff, sizeof(buff), stdin);
SetConsoleMode(hStdin, mode);
printf("You entered: %s", buff);
return 0;
}
In *nix you can use the "termios" interface to disable echo.
Code:
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
int main()
{
termios oldt;
tcgetattr(STDIN_FILENO, &oldt);
termios newt = oldt;
newt.c_lflag &= ~ECHO;
tcsetattr(STDIN_FILENO, TCSANOW, &newt);
fgets(buff, sizeof(buff), stdin);
tcsetattr(STDIN_FILENO, TCSANOW, &oldt);
printf("You entered: %s", buff);
return 0;
}
gg