I write that way, is the best way ?
Code:
if (NULL != pFile) {
fseek(pFile, 0, SEEK_END);
int size = ftell(pFile);
if (0 == size) {
printf("The file is empty \n");
exit(EXIT_FAILURE);
} else {
rewind(pFile);
}
}
I know what i should expect in the file.
nrfronteiras is unknow before i make fscanf and store the value in vector[i].nrfronteiras.
Code:
while (!feof(pFile)) {
fscanf(pFile, "%s %d %d", vector[i].idarea, &vector[i].pesocomportado, &vector[i].nrfronteiras);
for (int k = 0; k < vector[i].nrfronteiras; k++) {
vector[i].fronteiras[k] = malloc(MAX * sizeof (char));
fscanf(pFile, "%s", vector[i].fronteiras[k]);
}
In end i want to my program to detect a empty file and all the lines i read from the file are on the correct format.