Print * in place of characters for reading passwords in C

CServer Side ProgrammingProgramming

In this problem, we are given a string password. Our task is to print * in place of characters of the password.

Let’s take an example to understand the problem,

Input: password
Output
********

To solve this problem, we will traverse the password we have entered and print * in place of characters of the password.

Example

The below program will show the implementation of our solution

 Live Demo

#include <stdio.h>
#include <string.h>
int main() {
   char password[50] = "password";
   int length = strlen(password);
   printf("Password : ");
   for(int i = 0; i<length; i++){
      printf("*");
   }
   return 0;
}

Output

Password : ********
raja
Published on 03-Feb-2020 10:18:54
Advertisements