I have a program that processes calendar date type structures (day, month , year). How can I read the content of a file, regardless of the number of records in it?. at the moment, my code only reads the number of records I send as a parameter, which is not exactly correct and useful.
This is my function
void readN(struct data *element,int n){
FILE *data_file;
data_file = fopen("D:\\univer\\sem2\\tehProg\\struct_and_files\\data.txt","r");
if(data_file == NULL){
fprintf(stderr, "Unable to open file\n");
return;
}
for (int i = 0; i < n; i++) {
if (fscanf(data_file,"%d %d %d", &element[i].d, &element[i].m, &element[i].y) != 3){
fprintf(stderr, "Incomplete input!!!\n");
break;
}
}
fclose(data_file);
}
int main() {
struct data dd1[4];
readN(dd1,4);
return 0;
}
data.txt content
10 10 2001
1 1 2002
14 3 2004
18 4 2022
17 10 2002