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 5959965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T18:45:34+00:00 2026-05-22T18:45:34+00:00

How can I do so that I can display star(*) instead of plain text

  • 0

How can I do so that I can display star(*) instead of plain text for password in C++.

I am asking for password and it is plain pass on the screen.

How can I convert them in to star(*) so that user can not see the password while entering.

This is what I have currently

        char pass[10]={"test"};
        char pass1[10];
        textmode(C40);
        label:
        gotoxy(10,10);
        textcolor(3);
        cprintf("Enter password :: ");
        textcolor(15);
        gets(pass1);
        gotoxy(10,11);
        delay(3000);
        if(!(strcmp(pass,pass1)==0))
        {
          gotoxy(20,19);
          textcolor(5);
          cprintf("Invalid password");
          getch();
          clrscr();
          goto label;
        }

Thanks

  • 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-22T18:45:34+00:00Added an answer on May 22, 2026 at 6:45 pm

    You need to use an unbuffered input function, like getch () provided by curses library, or a console library of your OS. Calling this function will return the pressed key character, but will not echo. You can manually print * after you read each character with getch (). Also you need to write code if backspace is pressed, and appropriately correct the inserted password.

    Here is a code which once i wrote with the curses. Compile with gcc file.c -o pass_prog -lcurses

    #include <stdio.h>
    #include <stdlib.h>
    #include <curses.h>
    
    #define ENOUGH_SIZE 256
    
    #define ECHO_ON 1
    #define ECHO_OFF 0
    
    #define BACK_SPACE 127
    
    char *my_getpass (int echo_state);
    
    int main (void)
    {
      char *pass;
    
      initscr ();
    
      printw ("Enter Password: ");
      pass = my_getpass (ECHO_ON);
    
      printw ("\nEntered Password: %s", pass);
      refresh ();
      getch ();
      endwin ();
      return 0;
    }
    
    
    char *my_getpass (int echo_state)
    {
      char *pass, c;
      int i=0;
    
      pass = malloc (sizeof (char) * ENOUGH_SIZE);
      if (pass == NULL)
      {
        perror ("Exit");
        exit (1);
      }
    
      cbreak ();
      noecho ();
    
      while ((c=getch()) != '\n')
      {
        if (c == BACK_SPACE)
        {
          /* Do not let the buffer underflow */
          if (i > 0)
          { 
            i--;
            if (echo_state == ECHO_ON)
                   printw ("\b \b");
          }
        }
        else if (c == '\t')
          ; /* Ignore tabs */
        else
        {
          pass[i] = c;
          i = (i >= ENOUGH_SIZE) ? ENOUGH_SIZE - 1 : i+1;
          if (echo_state == ECHO_ON)
            printw ("*");
        }
      }
      echo ();
      nocbreak ();
      /* Terminate the password string with NUL */
      pass[i] = '\0';
      endwin ();
      return pass;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a legacy app that can display crystal reports to the user, using
I'm creating my own user control that can display n amount of images. Here
We have an iPhone app that can display an image dataset and pass it
I have an app that I have been developing that can display sensitive user
What is a good map API that can display not just a static image,
I have a batch script that can display two or more colors of text
Examotion has a player that can display the image for svg files as a
Possible Duplicate: Is there a tool that can display a SVN repository visually (
Does a smart textbox control (WinForms) exists that can display a path depending on
I'm looking for an SQL client app that can display subdatasheets like the following:

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.