ok heres the program, as i am a beginner, i wanted to learn why its written 13 and 9. and why when i replace the "char pass[9] to [8], the whole program goes to endless loop. if i am not wrong the [9] denotes the number of characters in the password but how come i can only put 8 char instead (if i add one more, the program will go to endless loop when i key in the correct password?
PHP Code:
void password(void)
{
char pass[9], password[9] = "pass1234"; /*password will be max at 8 characters*/
int num, repeat = 0;
Loop:
if (repeat > 2) /*if password enter incorrect 3 times, prompt and exit*/
{
clrscr();
mainpage();
gotoxy(30,30); printf("Check your password and try again.");
getch();
exit(1);
}
clrscr();
mainpage();
gotoxy(23,20);printf("Please Enter Password: ");
if (num != 9)
{
num = 0;
while ((pass[num] = getch()) != 13)
{
putchar('*');
num++;
}
pass[num] = '\0';
}
else
goto Loop;
if (strcmp(pass, password) == 0) /* password comparison
{
clrscr();
mainpage();
gotoxy(23,20);
printf("Access granted!");
getch();
menu();
}
else
{
clrscr();
mainpage();
gotoxy(23,22);
printf("Access denied!");
repeat++;
getch();
goto Loop;
}
}