So I've been working on this for some time now and can't seem to find the solution that works for me. I'm working in C/Unix. Basically, I want to take a user input and output something different. For example, I want to take a password and output *'s. In another instance, I want to take inputed numbers and output colored ones. I figured the colored numbers is the same as the password one, just using if statements.
Here's a code that I found online that seems to almost do the job, except I need it to output *'s as the user is typing something. Instead, it just stays blank.
#include <stdio.h>
#include <termios.h>
#include <unistd.h>
struct termios save;
void echoOff()
{
struct termios term;
tcgetattr( 0, &save );
term = save;
term.c_lflag &= (~ECHO);
tcsetattr( 0, TCSANOW, &term );
}
void echoOn()
{
tcsetattr( 0, TCSANOW, &save );
}
int main()
{
char password[30];
echoOff();
fgets( password, 30, stdin );
echoOn();
printf("Hello dude, your Password was: %s\n", password );
return 0;
}
Can anyone help me with this? Thanks!