In command prompt programming...
[list=1][*]How do you convert a user's input to asterisks as he/she is typing? [*]How do you detect if the user is typing characters that are non-numeric?[/list=1]
Thanks!
Rick
Printable View
In command prompt programming...
[list=1][*]How do you convert a user's input to asterisks as he/she is typing? [*]How do you detect if the user is typing characters that are non-numeric?[/list=1]
Thanks!
Rick
I've never done this so I can't be more help but for #1, youll have to hook the keyboard to get the data before the screen does... I do know you can do this though.
I figure #2 is answered by this, just compare the hooked data to your known asc codes
Google Search!
NOMAD
getch() will allow for you to input characters without echoing them to the screen. Then cout *'s to the screen for each character entered.
Now, if you want backspace, that is a bit difficult. If you are using Borland C++, clrscr() contained in conio.h (yes, i know that this header is depreciated but I do not have access to my complier right now to check.) will allow you to clear the screen and then redisplay your screen.
Now for #2:
if ((character <= 'a' && character >= 'z') && (character <= 'A' && character >= 'Z'))
// It is an alphabetic character. (If you are supporting different languages, check for valid characters the same way as I did above.)
conio.h isn't deprecated but it isn't standardized. clrscr is only available in Borland though.
x = getch(); //will get the character the user gave
if( (x >= 48) && (x <= 57) // this will check the input is numeric
if( (x < 48) && (x > 57) ) //do the opposite, non-numeric
<stdlib.h> ( im pretty sure thats it, if not its got some letters in front of it )
allows you to call
system("clr");
to clear the screen if you can't use clrscr();
system("cls");
The DOS clear screen app is called cls, not clr. In UNIX it would be "clear".
Cool! I'll try it out and let you know what happens.
Thanks, guys!
Rick