This program will accept a string from the user as a password, displaying *'s instead of the data entered by the user.
Lang: C
#include(stdio.h)
#include(conio.h)
#include(string.h)
void main() /* Or int main() with return 0 */
{
char pass[20];
int i;
printf("Enter password: ");
for(i=0; i<20; i+=1)
{
pass[i] = getch();
if(pass[i] == '\r') /* The carriage return escape sequence */
break;
printf("*");
}
pass[i] = '\0';
printf("\n");
if(strcmp(pass, "123")) /* Assume "123" is the correct password */
printf("Correct Password");
else
printf("Wrong Password");
getch();
}
Difficulty Rating: 3/10
For Creative Minds: Try using this with getche() instead of getch(). What changes will you have to make?
04 August, 2009
Accept a Password string, displaying it as *
Posted by Unknown at 9:22:00 PM
Labels: C, Escape Sequences, Strings
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment