Help answer threads with 0 replies.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-24-2004, 07:49 AM   #1
Registered: Jun 2004
Posts: 256

Rep: Reputation: 30
c related question.

how do I mask what a user type?

for example I have the following code:

char myPass[100];
printf("Input password: ");
scanf("%s"), myPass);

which will ask a user for an password. But I do not want the user's password to be seen when he typed on the screen. Prefer to mask it using "****" characters. How do I do that?
Old 07-24-2004, 08:55 AM   #2
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
Re: c related question.

#include <stdio.h>
#include <stdlib.h>
#include <termios.h>

static struct termios oldt;

void restore_terminal_settings(void)
    tcsetattr(0, TCSANOW, &oldt);  /* Apply saved settings */

void disable_echo(void)
    struct termios newt;

    tcgetattr(0, &oldt);  /* Save terminal settings */
    newt = oldt;  /* Init new settings */
    newt.c_lflag &= ~ECHO;  /* Change settings */
    tcsetattr(0, TCSANOW, &newt);  /* Apply settings */

int main()
    char myPass[100];

    printf("Input password: ");

    scanf("%s", myPass);

    return 0;
For an explanation about how it works see this thread:


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Boot-related question. wombat53 Slackware 55 06-21-2005 12:37 PM
SNAT related question Menestrel Linux - Networking 1 01-13-2005 10:56 PM
DNS related question tusher Linux - Newbie 1 12-07-2003 01:03 PM
DNS related question tusher Linux - Networking 1 12-01-2003 09:15 AM
question - DNS related rewt Linux - General 2 09-14-2001 10:19 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:59 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration