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?
Showing posts with label C. Show all posts
Showing posts with label C. Show all posts
04 August, 2009
Accept a Password string, displaying it as *
Posted by Unknown at 9:22:00 PM 0 comments
Labels: C, Escape Sequences, Strings
Subscribe to:
Posts (Atom)