'I have exception thrown error when I try to printf

Exception thrown at 0x00007FFD4B79FAAD (ntdll.dll) in IPC Final.exe: 0xC0000005: Access violation writing location 0x00007FF71469C5D8.

When I tried to print, I got this message. I am trying to open a file, store the value of file to struct, and print the value of the struct. I could see the local variable value, but I could not to print them.

enter code here void displayAll(struct WeatherRecord* data, int max){
int total = 0;
displayHeader(FMT_WHOLE);
struct WeatherRecord temp[MAX_RECORD] = { 0 };
FILE* file = fopen("weatherdata.txt", "r");
total = importWeatherDataFile(file, temp, max);
fclose("weatherdata.txt");
temp[1].date.year;
printf("%d", temp[1].date.year); // the call stack appeared here
printf("%d  %d  %lf  %c  %d  %s", data[0].date.year, data[0].date.month,
    data[0].precipAmt, data[0].unit,
    data[0].location.regionCode,
    data[0].location.name);}


Solution 1:[1]

The call stack is referring to the previous line. fclose does not accept a file name, it accepts a FILE pointer.

fclose(file);

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Tim Roberts