Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6193233
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T03:05:00+00:00 2026-05-24T03:05:00+00:00

I want to mask my password while writing it with * . I use

  • 0

I want to mask my password while writing it with *.
I use Linux GCC for this code.
I know one solution is to use getch() function like this

#include <conio.h>   
int main()
{
    char c,password[10];
    int i;
    while( (c=getch())!= '\n');{
        password[i] = c;
        printf("*");
        i++;
    }
    return 1;
}

but the problem is that GCC does not include conio.h file so, getch() is useless for me.
Does anyone have a solution?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T03:05:00+00:00Added an answer on May 24, 2026 at 3:05 am

    In the Linux world, masking isn’t usually done with asterisks, normally echoing is just turned off and the terminal displays blanks E.g. if you use su or log into a virtual terminal etc.

    There is a library function to handle getting passwords, it won’t mask the password with asterisks but will disable echoing of the password to terminal. I pulled this out of a linux book I have. I believe its part of the posix standard

    #include <unistd.h>
    char *getpass(const char *prompt);
    
    /*Returns pointer to statically allocated input password string
    on success, or NULL on error*/
    

    The getpass() function first disables echoing and all processing of
    terminal special characters (such as the interrupt character, normally
    Control-C).

    It then prints the string pointed to by prompt, and reads a line of
    input, returning the null-terminated input string with the trailing
    newline stripped, as its function result.

    A google search for getpass() has a reference to the GNU implementation (should be in most linux distros) and some sample code for implementing your own if need be

    http://www.gnu.org/s/hello/manual/libc/getpass.html

    Their example for rolling your own:

    #include <termios.h>
    #include <stdio.h>
    
    ssize_t
    my_getpass (char **lineptr, size_t *n, FILE *stream)
    {
        struct termios old, new;
        int nread;
    
        /* Turn echoing off and fail if we can't. */
        if (tcgetattr (fileno (stream), &old) != 0)
            return -1;
        new = old;
        new.c_lflag &= ~ECHO;
        if (tcsetattr (fileno (stream), TCSAFLUSH, &new) != 0)
            return -1;
    
        /* Read the password. */
        nread = getline (lineptr, n, stream);
    
        /* Restore terminal. */
        (void) tcsetattr (fileno (stream), TCSAFLUSH, &old);
    
        return nread;
    }
    

    If need be you could use this as the basis as modify it to display asterisks.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

want to know why String behaves like value type while using ==. String s1
How can I mask input from the command line? Basic use case: I want
I want to use the MaskedEditExtender to mask short dates. The problem is that
I have a webform gridview. In that one columns is password. I want to
I want to draw an alpha mask image in code. Right now I do:
I want to use an alpha mask in OpenGL so that white(1)=visible and black(0)=hidden.
I want to mask a password. I used System.console() but it is not better
I want to remove or mask password from some confidential files. I am using
I am writing a Linux CLI program. I need to get a password from
I want to mask a widget. So i used a popup panel to do

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.