Skip to content
Related Articles

Related Articles

Print * in place of characters for reading passwords in C

View Discussion
Improve Article
Save Article
Like Article
  • Difficulty Level : Easy
  • Last Updated : 20 Sep, 2018

While writing a C program, if you want to type password and it should not be visible on screen or an * symbol is to be printed.


Input : abcdefg
Output : *******

Note : Below solution uses getch() which may not work on all compilers as this is a non-standard function.

// C program to print * 
// in place of characters
int main(void){
    char password[55];
    int p=0;
    printf("\nYou have entered %s as password.",password);

Explanation: Basically it is taking the characters we enter through getch() function and print * instead of it for every letter we type.

Remark: It doesn’t run in this IDE, download this file and run in your terminal.

This article is contributed by Pavan Gopal Rayapati. If you like GeeksforGeeks and would like to contribute, you can also write an article using or mail your article to See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please write comments if you find anything incorrect, or you want to share more information about the topic discussed above.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!