Dladu
10-18-2007, 10:43 PM
Well im trying to in c++ get the input but dont echo it to the screen but display * instead, also if the backspace key is pressed then delete an astericks and if there is nothing there, beep at you. Also if you use the arrow keys or space bar it beeps at you and does not work as there can't be spaces in this input
I was trying to use getch in a loop before the input but I couldn't get that to work so I was thinking I probably need to make a function where I have no clue where to start inorder to make that happen :P
have this so far
fflush(stdout);
int z = 0, ch, first;
char password4[100];
while ((ch = getch()) && ch != '\n' && ch != '\r'
&& z < sizeof(password4) - 1)
{
if (ch == '\b' && z > 0)
{
cout << "\b \b";
fflush(stdout);
z--;
password4[z] = '\0';
}
else
{
if (z == 0 && ch == '\b')
{
if( ch == '\b')
{
cout << "\a";
}
}
first = 2;
if ( z > 0 || first == 2 && ch != '\b' )
{
cout << "*";
password4[z++] = ch;
}
}
}
cout << "\n\n";
password4[z] = '\0';
I was trying to use getch in a loop before the input but I couldn't get that to work so I was thinking I probably need to make a function where I have no clue where to start inorder to make that happen :P
have this so far
fflush(stdout);
int z = 0, ch, first;
char password4[100];
while ((ch = getch()) && ch != '\n' && ch != '\r'
&& z < sizeof(password4) - 1)
{
if (ch == '\b' && z > 0)
{
cout << "\b \b";
fflush(stdout);
z--;
password4[z] = '\0';
}
else
{
if (z == 0 && ch == '\b')
{
if( ch == '\b')
{
cout << "\a";
}
}
first = 2;
if ( z > 0 || first == 2 && ch != '\b' )
{
cout << "*";
password4[z++] = ch;
}
}
}
cout << "\n\n";
password4[z] = '\0';