I am quite new to coding so please go easy on me
Here's my code
/* Open File*/
FILE *openFile(char filename[], char filetype[]);
/* Read Number Of Nurses */
int readNurses(void);
/* Title */
void title(void);
/* Login Screen*/
int loginScreen();
/* Checks if memory allocation was correct */
void mallocCheck(char **malloc1, char **malloc2);
/* Asks for login details */
int askLogin(void);
/* Retrieve Login Details */
void getDetails(char **properID, char **properPASS, int nurses);
/* Test Details Input To Details */
int testDetails(void);
/* Encryption Of Password */
void encryptPass(void);
/* Main Menu */
void mainMenu(void);
/* Encrypt Patient's Details */
void encrtpyPatient(void);
/* Enter Patients Details */
void enterPatients(void);
/* Create Patients File */
void createPatient(void);
/* Clear Screen Smooth */
void clearScreen(void);
int main(void)
{
int nurses;
int correct;
char enterID[ID_LENGTH];
nurses = readNurses();
correct = loginScreen(enterID, nurses);
title();
return 0;
}
void title(void)
{
printf("\n\n\n =================================");
Sleep(SLEEP_TIME);
printf("\n = =");
Sleep(SLEEP_TIME);
printf("\n = Welcome to Action On Weight =");
Sleep(SLEEP_TIME);
printf("\n = =");
Sleep(SLEEP_TIME);
printf("\n =================================");
Sleep(SLEEP_TIME);
printf("\n *****************");
printf("\n ****** ******");
printf("\n **** ****");
printf("\n **** ***");
printf("\n *** ***");
printf("\n ** *** *** **");
printf("\n ** ******* ******* **");
printf("\n ** ******* ******* **");
Sleep(SLEEP_TIME);
printf("\n ** ******* ******* **");
printf("\n ** *** *** **");
printf("\n ** **");
printf("\n ** * * **");
printf("\n ** ** ** **");
printf("\n ** *** *** **");
printf("\n ** * * **");
printf("\n ** *** *** **");
Sleep(SLEEP_TIME);
printf("\n *** **** **** ***");
printf("\n ** ****** ****** **");
printf("\n *** *************** ***");
printf("\n **** ****");
printf("\n **** ****");
Sleep(SLEEP_TIME);
printf("\n ****** ******");
printf("\n *****************");
Sleep(SLEEP_TIME);
Sleep(SLEEP_TIME);
}
int readNurses(void)
{
FILE *fin;
int nurses;
fin = openFile("Nurses.txt", "r");
while(!feof(fin))
{
fscanf(fin, "%*s");
nurses++;
}
fclose(fin);
printf("%d", nurses);
return nurses;
}
FILE *openFile(char filename[], char filetype[])
{
FILE *ptr = fopen(filename, filetype);
if(!ptr)
{
printf("\n\n\n Error 1. File couldn't be opened.");
(" Please contact us at email@example.com");
exit(1);
}
return ptr;
}
int loginScreen(char enterID[], int nurses)
{
int correctDetails;
int loop;
char *properID;
char *properPASS;
properID = (char*) malloc(ID_LENGTH * nurses * 60);
properPASS = (char*) malloc(PASS_LENGTH * nurses *60);
correctDetails = 0;
mallocCheck(&properID, &properPASS);
getDetails(&properID, &properPASS, nurses);
loop = nurses - 1;
printf("das");
while(nurses > 0)
{
printf("%s : %s", &properID[nurses], &properPASS[nurses]);
nurses--;
}
/* do
{
printf("\n\n\n ================================");
printf("\n = =");
printf("\n = Login Screen =");
printf("\n = =");
printf("\n ================================");
}while(correctDetails = 0); */
while(loop > 0)
{
free(properID - loop);
free(properPASS - loop);
loop--;
}
return correctDetails;
}
void mallocCheck(char **malloc1, char **malloc2)
{
if(malloc1 == NULL ||malloc2 == NULL)
{
printf("\n\n\n Error 2. Assignment of ");
printf(" memory wasn't succcesful.");
printf(" Please contact us at email@example.com");
Sleep(SLEEP_TIME);
Sleep(SLEEP_TIME);
exit(0);
}
}
void getDetails(char **properID, char **properPASS, int nurses)
{
FILE *ptr;
ptr = openFile("Nurses.txt", "r");
while(!feof(ptr))
{
fscanf(ptr, "%[^.]%*c%s\n",
&properID[nurses], &properPASS[nurses]);
nurses--;
}
fclose(ptr);
}
The problem is in function loginScreen(), the function getDetails() get run, but then once it finishes 3221225477, can anyone point me out to why this is happening? It looks like I am allocating memory and everything properly. I have tried to find out why this is happening but I couldn't find anything.