I have the following code:
_Bool grantAccess(char *password){
char goodPassWord[]= "goodpass";
return (0 == strcmp(password, goodPassWord));
}
_Bool grantAccessExercise(void){
char password[9];
int allow = 0;
printf("Please enter password: ");
gets(password);
if (grantAccess(password)) {
allow = 1;
}
return (allow != 0);
}
When I enter any combination of 10 characters for password it overflows and overwrites the null-terminator. Can anyone explain why the non null-terminated value causes StrCmp to return 0?