OK, so the 2nd is correct?
This is the code:
datebook is a struct that has year, month, day, hour and minutes of the booking
in patientAux I save the patient I'm looking to eliminate
Code:
void copyBookings(tClinic* clinic){
int id;
char DNI[MDNI];
tdate datebook;
tBook* bookAux;
tPatient* patientAux;
tLista* Lista;
FILE* fbooks;
fbooks = fopen(TURNOSFILE, "wb+");
while(fread(&id, sizeof(int), 1, fbooks)){
bookAux = initializebook();
fread(DNI, sizeof(char)*MDNI, 1, fbooks);
fread(&datebook.yyyy, sizeof(int), 1, fbooks);
fread(&datebook.mm, sizeof(int), 1, fbooks);
fread(&datebook.dd, sizeof(int), 1, fbooks);
fread(&datebook.hora, sizeof(int), 1, fbooks);
fread(&datebook.min, sizeof(int), 1, fbooks);
patientAux = searchByID(clinic, DNI);
Lista = searchSpecByID(clinic, id);
bookAux->patient->name = (char*)malloc(sizeof(char) * (strlen(patientAux->name) + 1));
strcpy(bookAux->patient->dni, patientAux->dni);
bookAux->patient->sexo = patientAux->sexo;
strcpy(bookAux->patient->name, patientAux->name);
bookAux->date.yyyy = datebook.yyyy;
bookAux->date.mm = datebook.mm;
bookAux->date.dd = datebook.dd;
bookAux->date.hora = datebook.hora;
bookAux->date.min = datebook.min;
addToList(Lista, bookAux);
printbooking(bookAux, id);
}
fclose(fbooks);
}
Thanks!!!!!!