Setting up a database which takes the input from a user(First name, last name, ID number , etc..) and inputs the information into a binary file, to update information , delete records, and update any information provided. All other functions seem to be functioning properly(Dont mind the bad code, im fairly new to programming) besides the function to display the non empty records. the information seems to be getting saved into the files because the other functions have access to it(all the same file pointer). I've checked to see if the file was being overwritten by the initialization of the empty file and that hasn't been the case to my understanding.
I've checked to see if the file was being overwritten by the initialization of the empty file and that hasn't been the case to my understanding. I've also tried updating the the if statement in the DisplayRecord function so that it would read all files and display only the ones that have an established ID number but it still shows null when the function is ran.
// fopen opens the file; exits if file cannot be opened
if ((cPtr = fopen("patient.dat", "rb")) == NULL) {
puts("File could not be opened.");
}//end If
else {
printf( "Patient ID\t Last Name\t first name\t DOB \tGender\t Doctor ID\t
Doctor last name\t Room Number\n" );
struct PatientData {
unsigned int Pat_ID; //ID number
char F_Name[25];//first name
char L_Name[25]; //last name
char Phone_num[20] ; //Phone number
char gender[2];
unsigned int doctor_ID;
char doc_LN[25];
unsigned int room_num;
char DoB[10];
};
//read all records until eof
while(!feof(cPtr)){
//create blank set to compare to data on file
struct PatientData Patient= { 0, "","","","",0,"", 0,"" };
int result=fread(&Patient,sizeof(struct PatientData), 1 , cPtr);
if(result!=0 && Patient.Pat_ID!=0){
printf("%-d%-15s%-15s%-10s%-12s%-15d%-15s%-10d\n",
Patient.Pat_ID,
Patient.L_Name,Patient.F_Name,Patient.DoB,Patient.gender,
Patient.doctor_ID, Patient.doc_LN,Patient.room_num);
}
fclose(cPtr); // fclose closes the file
Its suppose to display all records that have information in it. but the actual output is not showing any records.