Code:
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(int argc, char *argv[])
{
int i, z, q;
int ctr = 0;
char password[] = "Password";
char entry[20];
printf("To get into the program, you must enter the correct password.\n");
printf("Type in your password(upper and lower case matter).\n");
/* fgets(entry, sizeof entry, stdin);
perhaps you might need this as well if you use fgets
char *p;
p = strchr(entry,'\n');
P = '\0';
*/
gets(entry);
i = strlen(password);
printf(" %d\n", i);
for(z=0; z <= i; z++)
{
if(password[ctr] == entry[ctr])
q++;
ctr++;
}
if(q == i)
printf("You are in\n");
else
printf("Access denied\n");
/* use getchar(): */
system("PAUSE");
return 0;
}
/* my output
To get into the program, you must enter the correct password.
Type in your password(upper and lower case matter).
Password
8
Access denied
Press any key to continue . . .
*/
Perhaps you could display the chars enetred with '*' as an improvement to your code.
ssharish2005