I have some problem in "fcanf" function. i'm new in C, and i wanted to make reading lines from the file and save them to structure, but it seems, that i dont understand it well ^^.
PATIENT *patientTab;
int tabSize = 0;
int patientCount = 0;
PATIENT temp;
int tempIndex = 0;
if (openFile()){
printf("Plik otworzony!nn");
while(fscanf(dataBase, "%s %f",
&temp.patientNumber,
&temp.patientGender,
&temp.patientLength,
&temp.patientWeigth,
&temp.patientHeadCircuit,
&temp.patientApperance,
&temp.patientPulse,
&temp.patientGrimace,
&temp.patientActivity,
&temp.patientRespiration)
!= EOF){
if (patientCount + 1 >= tabSize){
tabSize += 5;
patientTab = realloc(patientTab, sizeof(int) * tabSize);
}
for (tempIndex; tempIndex < 5; tempIndex++){
patientTab[patientCount].patientNumber[tempIndex] = temp.patientNumber[tempIndex];
}
patientTab[patientCount].patientGender = temp.patientGender;
patientTab[patientCount].patientLength = temp.patientLength;
patientTab[patientCount].patientWeigth = temp.patientLength;
patientTab[patientCount].patientHeadCircuit = temp.patientHeadCircuit;
patientTab[patientCount].patientApperance = temp.patientApperance;
patientTab[patientCount].patientPulse = temp.patientPulse;
patientTab[patientCount].patientGrimace = temp.patientGrimace;
patientTab[patientCount].patientActivity = temp.patientActivity;
patientTab[patientCount].patientRespiration = temp.patientRespiration;
patientCount++;
}
//free(temp);
fclose(dataBase);
}
else endProgram();
dataBase is global.
The problem is, when program tries to loop "while", which include "fscanf" function, program is casting an error and the only think, which i can do is shut down program. I found this way in the Internet, but there was a simply example with one variable. I'm sure the problem is my declaration with many parameters with "&temp".
The structure is:
typedef struct Patient {
char patientNumber[5];
char patientGender;
double patientLength;
float patientWeigth;
float patientHeadCircuit;
int patientApperance;
int patientPulse;
int patientGrimace;
int patientActivity;
int patientRespiration;
}PATIENT;
...and this is fragment of content file: txt link
Aucun commentaire:
Enregistrer un commentaire