After making the said changes, a number of other issues have occurred. One is that the only user that can log in is the first one in the text file. I apologize if the solution is simple, I am new to coding. the text file of users contains a list of usernames and passwords formatted as
USERNAME:PASSWORD \n USERNAME2:PASSWORD2
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define NAMELENGTHS 20
#define TEXTLENGTHS 200
#define PASSWORDS 8
struct patients
{
char username[NAMELENGTHS];
char password[PASSWORDS];
};
void emptyBuffer(void);
void addDetails(struct patients list[], int i);
int main(void)
{
FILE *fin;
struct patients list[20];
char usernameIN[NAMELENGTHS];
char userInput[PASSWORDS];
int noPatients = 0, i = 0;
if(!(fin = fopen("passwords.txt", "r")))
{
printf("File not detected\n");
return 1;
}
while(fscanf(fin,"%19[^:]:%7[^\n]", list[noPatients].username,
list[noPatients].password)
== 2)
{
noPatients++;
}
fclose(fin);
printf("please enter a username: ");
scanf("%s", usernameIN);
emptyBuffer();
printf("Please enter a password: ");
scanf("%s", userInput);
emptyBuffer();
while(i < noPatients)
{
if(strcmp(usernameIN, list[i].username) == 0 &&
strcmp(userInput, list[i].password) == 0)
{
printf("Log in successful.\n");
int menuOption;
do
{
printf("\n--------------------------------\n");
printf("Main Menu");
printf("\n--------------------------------\n");
printf("1. Add Details\n");
printf("2. Read Details\n");
printf("3. Exit program\n");
scanf("%d", &menuOption);
emptyBuffer();
switch(menuOption)
{
case 1:
addDetails(list, noPatients);
break;
case 2:
printf("option 2");
break;
case 3:
return 0;
default:
printf("\nInvalid Input");
break;
}
}while(menuOption != 3);
}
i++;
}
printf("log in failed");
return 0;
}