masking characters 
Author Message
 masking characters

How do you mask a character the user types in to something like this '*' in C?
Let's say that you typed in 'a', but it would show up as '*'.  How would you do
that?



Mon, 13 Nov 2000 03:00:00 GMT  
 masking characters

Quote:

> How do you mask a character the user types in to something like this '*' in C?
> Let's say that you typed in 'a', but it would show up as '*'.  How would you do
> that?

There is absolutely no way to do that as far as I'm concerned.  Your
compiler might disagree with me, though, so ask it.

--

I believe we can change anything.
I believe in my dream.
    - Joe Satriani



Mon, 13 Nov 2000 03:00:00 GMT  
 masking characters


Quote:
>How do you mask a character the user types in to something like this '*' in C?
>Let's say that you typed in 'a', but it would show up as '*'.  How would you do
>that?

You can't do this with only the I/O facilities defined by the C language.
You must turn to system-specific extensions.


Mon, 13 Nov 2000 03:00:00 GMT  
 masking characters


:
:>How do you mask a character the user types in to something like this '*' in
C?
:>Let's say that you typed in 'a', but it would show up as '*'.  How would you
do
:>that?
:
:   In Borland C you can use the 'getch' function to get a character
:from the keyboard without echoing it to the screen.  Each time getch
:gets a keyboard character then output  a '*' to the screen for example
:using the 'putch' function. If this is for password entry then you
:will probbaly need to handle  a few typed characters like backspace,
:carriage return etc separately so that the password entry can be
:edited by a user.  I think these are all standard functions in the
:console i/o library.
============
On the contrary, all of these are non-standard functions in the
non-standard <conio.h> header and associated libraries.
They do not belong in comp.lang.c
============
:
:



Wed, 15 Nov 2000 03:00:00 GMT  
 masking characters


Quote:
>How do you mask a character the user types in to something like this '*' in C?
>Let's say that you typed in 'a', but it would show up as '*'.  How would you do
>that?

Why don't you use "getch()"
getch() will not show anything while getting user input.  
So all you have to do is:

  Get user input with getch() and process each character with
switch(). Then add followings inside the switch();

    if user input an alpha-numeric  character, print an '*' on screen.
    if user press "backspace", delete an '*' on the screen.

To learn more about "getch()", consult your compiler's help.



Fri, 17 Nov 2000 03:00:00 GMT  
 masking characters


:
:>How do you mask a character the user types in to something like this '*' in
C?
:>Let's say that you typed in 'a', but it would show up as '*'.  How would you
do
:>that?
:
:Why don't you use "getch()"
:getch() will not show anything while getting user input.
:So all you have to do is:
==========
Why don't you get the FAQ from ftp://rtfm.mit.edu/pub/usenet-by-group
and read it.  Then your postings will show less flammage and
you will do less damage.
==========
:
:  Get user input with getch() and process each character with
:switch(). Then add followings inside the switch();
:
:    if user input an alpha-numeric  character, print an '*' on screen.
:    if user press "backspace", delete an '*' on the screen.
:
:To learn more about "getch()", consult your compiler's help.
:
:



Fri, 17 Nov 2000 03:00:00 GMT  
 masking characters

Quote:


> >How do you mask a character the user types in to something like this '*' in C?
> >Let's say that you typed in 'a', but it would show up as '*'.  How would you do
> >that?

> Why don't you use "getch()"

Because there is no such function in standard C.

Quote:
> getch() will not show anything while getting user input.

No, getch() on YOUR compiler will do that.

Quote:
> So all you have to do is:

>   Get user input with getch() and process each character with
> switch(). Then add followings inside the switch();

>     if user input an alpha-numeric  character, print an '*' on screen.

How would you do that in a switch?

    case 'a':
    case 'b':
    case 'c':
    case 'd':
    ...
    case '0':
    case '1':
    ...
    etc., etc.

?

There's a perfectly good function called isalnum() which will tell you
if a character is alpha-numeric or not.  It will most likely be faster,
smaller, and more portable than anything you can write.

Quote:
>     if user press "backspace", delete an '*' on the screen.

> To learn more about "getch()", consult your compiler's help.

In comp.lang.c we only accept portable, standard answers.  getch()
doesn't exist in standard C, and doesn't even exist in nearly as many
compilers as it used to, so it doesn't have any place in this newsgroup.

--

I believe we can change anything.
I believe in my dream.
    - Joe Satriani



Fri, 17 Nov 2000 03:00:00 GMT  
 masking characters



Quote:

>>How do you mask a character the user types in to something like this '*' in C? >>Let's say that you typed in 'a', but it would show up as '*'.  How would you do>>that?

>Why don't you use "getch()"
>getch() will not show anything while getting user input.  
>So all you have to do is:

The problem is that the C language doesn't have a getch() function. See the
FAQ for more details.

--
-----------------------------------------


-----------------------------------------



Fri, 17 Nov 2000 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. Edits with character masks

2. HELP - ActiveX Masked Edit Control does NOT accept mask

3. multi-character character constant

4. Support for characters not in default character set?

5. Delete each character in s1 that matches any character in s2

6. Character signedness, character classification and table lookups

7. parsing a string character by character

8. Converts a sequence of wide characters to a corresponding sequence of multibyte characters

9. Const Character to character conversion.

10. Get ASCII character code of a character

11. Add hex-digit mask to MS Masked Edit OCX control?

12. Subnet mask - please help!

 

 
Powered by phpBB® Forum Software