I have such a function that reads all the contents of the data file.txt, which contains variables of the given structure type, in the format DD mm yyyy. this is the function
void readFromFile(struct data *element){
FILE *data_file;
data_file = fopen("D:\\univer\\sem2\\tehProg\\struct_and_files\\struct.txt","rw");
if(data_file == NULL){
fprintf(stderr, "Nu se poate de deschis fisierul\n");
return;
}
char line[100];
while (fgets(line, sizeof line, data_file))
{
int y, m, d;
if (sscanf(line, "%d %d %d", &d,&m,&y))
{
element[n].d = d;
element[n].m = m;
element[n].y = y;
++n;
}
}
fclose(data_file);
}
For this, I assign memory to the variable DD1, and transmit it as a paramatron in my function, from main.
struct data *dd1 = malloc(sizeof *dd1);
readFromFile(dd1);
displayN(dd1);
struct data maximum = checkMax(dd1);
struct data minimum = checkMin(dd1);
printf("\n Data maxima %d %d %d",maximum.d,maximum.m,maximum.y);
printf("\n Data minima %d %d %d", minimum.d,minimum.m,minimum.y);
printf("\n Nr de ani bisecti : %d ", checkLeapYear(maximum,minimum));
free(dd1);
Everything works, but I get this error code (-1073741819 (0xC0000005)) in the console. What could be the cause?