-1

I want to know how to take characters from the console using

scanf, getch()

or something else and at the time that the user gives the input I want the screen to show:

******

for every character.

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278

1 Answers1

1

If you are on Windows, I think you can use something like given below -

#include <stdio.h>
#include <conio.h>
int main(){
    char str[8];
    int i=0;
    printf("Enter the password :\n");
    while (i< 8){
        str[i]=getch();
        printf("*");
        i++;
    }
    str[i]='\0';
    return 0;
}

The getch() function is not so readily available on Unix-like systems. (The curses or ncurses library provides a function getch(), but you have to call functions to setup the terminal correctly, and then reset it back to a known state.)

Jonathan Leffler
  • 730,956
  • 141
  • 904
  • 1,278
Ajesh
  • 193
  • 8