Print * in place of characters for reading passwords in C


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 : ********

Updated on: 03-Feb-2020

440 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements