Facing Problem with the Login Function
The code I'm writing is a login function in C programming, using this code, although the email that I have entered is already match with the email in the binary file, but my program keep telling me invalid email how to solve this ?? thank you so much !!!
//tagged structure global
struct Birthday {
int day, year;
char month[10];
};
//typedef structure global
typedef struct {
char icNo[15];
struct Birthday staffBDay;
char email[50];
char contactNo[15];
char password[15];
char position[30];
char faculty[10];
}StaffPrivInfo;
//Structure variable global
struct {
char staffId[15];
char name[30];
char gender;
StaffPrivInfo privInfo;
}staffInfo, modifyInfo[30];
int main() {
char loginEmail[50], loginPass[15];
//binary file pointer declaration
FILE* loginPtr;
//open binary file for reading
loginPtr = fopen("staffInfo.dat", "rb");
//check whether the binary file is exist
if (loginPtr == NULL) {
printf("Unable to append staffInfo.dat file !\n");
exit(-1);
}
printf("WELCOME TO ADMINISTRATIVE STAFF MODULE !!!\n\n");
printf("Login\n");
printf("======\n");
while (fread(&staffInfo, sizeof(staffInfo), 1, loginPtr) != 0) {
printf("Email: ");
rewind(stdin);
scanf("%[^\n]", &loginEmail);
if (strcmp(loginEmail, staffInfo.privInfo.email) == 0) {
printf("Password: ");
rewind(stdin);
scanf("%[^\n]", &loginPass);
if (strcmp(loginPass, staffInfo.privInfo.password) == 0) {
printf("Successfully Login!!!\n\n");
staffMainMenu();
}
else {
printf("Incorrect Password\n\n");
}
}
else if(strcmp(loginEmail, staffInfo.privInfo.email) != 0) {
printf("Invalid Email !!! Please Re-enter Email: ");
rewind(stdin);
scanf("%[^\n]", &loginEmail);
}
}
staffMainMenu(); }