I am trying to read and compare some data from a text file. The text file looks like the following where the white space is different between each line:
Username Password
Maolin 111111
Jason 222222
Mike 333333
I have the following code which works if the white space is only a single " " space.
bool authenticate_login(char *username, char *password)
{
FILE *file;
char *file_username;
char *file_password;
bool match;
if ((file = fopen("Authentication.txt", "r")) == NULL) {
perror("fopen");
return false;
}
while (fgetc(file) != '\n'); /* Move past the column titles in the file. */
while (fscanf(file, "%s %s\n", file_username, file_password) > 0) {
if (strcmp(file_username, username) == 0 && strcmp(file_password, password) == 0) {
match = true;
break;
}
}
printf("\nMade it here babe %d", match);
fclose(file);
return match;
}
Can someone please show me how to change my code so that I can ignore the white space regardless of how much there is?