By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,157 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

how to hide characters on screen

P: n/a
Hi,
Can someone guide me as to how I can modify the code below to hide
characters from displaying on the screen as they are entered? If there is
a better way of achieving this, please let me know.

I'm running this on unix (Solaris8).

thanks.

#include <stdio.h>

int main(void)
{
int passwdstr;

printf ( "Enter password: ");
while ( ( passwdstr=getchar() ) != '\r' ) {
putchar ('*');
}
return 0;
}

Nov 14 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
torno wrote:

Can someone guide me as to how I can modify the code below to hide
characters from displaying on the screen as they are entered?
If there is a better way of achieving this, please let me know.

I'm running this on unix (Solaris8).

#include <stdio.h>

int main(void) {
int passwdstr;

printf ( "Enter password: ");
while ( ( passwdstr=getchar() ) != '\r' ) {
putchar ('*');
}
return 0;
} cat main.c #include <unistd.h>
#include <stdio.h>

int main(int argc, char* argv[]) {
char *getpass(const char* prompt);
fprintf(stdout, "password = %s\n",
getpass("Enter password: "));
return 0;
}
gcc -Wall -std=c99 -pedantic -o main main.c
./main

Enter password:
password = password
Nov 14 '05 #2

P: n/a
"E. Robert Tisdale" <E.**************@jpl.nasa.gov> wrote:
torno wrote:
Can someone guide me as to how I can modify the code below to hide
characters from displaying on the screen as they are entered?
If there is a better way of achieving this, please let me know.
Read the FAQ. The FAQ is your friend.
<http://www.eskimo.com/~scs/C-faq/q19.1.html>. Admittedly, the way this
question is phrased in the index for section 19 is incomplete; but a
search of the text version (posted here regularly) on "password"
would've turned up this question.
> cat main.c #include <unistd.h>


This is not ISO C, and therefore off-topic.
char *getpass(const char* prompt);
This is not ISO C, and therefore off-topic. Moreover, function
declarations within other functions (yes, even within main()) are a Bad
Thing.
getpass("Enter password: "));


This is not ISO C, and therefore off-topic.
> gcc -Wall -std=c99 -pedantic -o main main.c


We don't care what your broken compiler says, it's still off-topic.

I'd tell you to read the bloody FAQ, as well, but in your case it would
probably be a waste of time, since you don't appear to give a damn.

Richard
Nov 14 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.