2

I am writing C code for 'password prompt' . I need to display * for every character the user enters . But I am not supported with getch(). So , I tried system calls .

for(i=0;i<5;i++)
{
    system("stty -echo");
    scanf("%c", &a[i]);
    system("stty echo");
    printf("*");
}

I have tried to turn off echo and get a char and display * enabling echo. But we know scanf continues until \n. So , i am unable to display * at once a char is got. Somebody help me pls. Also kindly suggest me any other better way.

hek2mgl
  • 152,036
  • 28
  • 249
  • 266
  • 1
    [Related question](http://stackoverflow.com/questions/6856635/hide-password-input-on-terminal). – Lundin Sep 17 '13 at 09:27

1 Answers1

0

Typing a password without echo at all is relatively easy, but displaying stars one character at a time isn't (doing that while supporting backspace -- or worse, arrow keys -- is even harder).

The first step is to "set the terminal in RAW mode" to disable the "wait for a full line" behavior.

Medinoc
  • 6,577
  • 20
  • 42