When you type a key or pass, how can you make it so it displays as ******
Thanks
When you type a key or pass, how can you make it so it displays as ******
Thanks
This would be good to put on the faq if it isnt alerady there.Code://ENTERING PASSWORD //DECLARE USERPASSWORD[] AND SET IT ALL TO '\0' int u = 0; char a ; while (1){ a=getch(); if (int(a)==13){ //13 = enter userpassword[u]='\0'; break; } if (int(a)==8){ //8 = backspace userpassword[u-1]='\0'; u--; putchar('\b'); putchar(' '); putchar('\b'); } else { printf("*"); userpassword[u]=a; u++; } }
Actually I was able to cut that down a few lines.
Code://ENTERING PASSWORD //DECLARE USERPASSWORD[] AND SET IT ALL TO '\0' int u = 0; while (1){ char a=getch(); if (int(a)==13){ //13 = enter userpassword[u]='\0'; break; } else if (int(a)==8){ //8 = backspace userpassword[--u]='\0'; putchar('\b',' ',\b'); } else { printf("*"); userpassword[u++]=a; } }
Last edited by tim545666; 02-16-2002 at 10:45 PM.
that's bad programming...
try converting most of the if statements to a switch function:
example:
int x;
cin>>x;
switch(x)
{
case 0: cout<<"hey, you entered a zero... "; break;
default: cout<<x; break;
}
...
Why is it bad? I agree that if if-else statements get too big, they are unreadable, but in this case an if-else will do. According to my comp sci teacher, switch statements are slower and sort of clunky. I don't see a point to a switch here. Actually I found another error. I'll edit my previous post.
could you possibly write the code for C++, cuz printf("blah blah").. isnt that C? yea im a noob...
Printf is C, but it can also be used in C++. I was using cout but it was giving me problems so I used printf. The rest is pure C++, except for maybe putchar, that may be C. I never learned C so I don't know.
I'm a noob too, don't worry about it.
Tim...The printf and putchar are giving me errors, the error message is call to undefined function, i changed printf to cout and that worked but putchar is still giving me an error.