I am writting a prohram that declares a struct with 3 ints and 1 float called weather_t. I must read the data in from a txt file for 12 months of data which would be 48 numbers. I need 2 functions one that load the stats- int loadstats and one that prints the stats. Main is declaring the array and open and closing the data. My problem is I am using a loop to take the data from the file and trying to load it into the array using fread with a file pointer.
I would think reading it in 4 peices at a time would be appropiate because there is 4 per month. The next step is trying to pass that data and loaded into the struct with the function- it doesdn't like (fp, weather_t) and for print purposes it doesn't like weather_t wdata
Code:
#include <stdio.h>
typedef struct {
int avg_high_temp;
int avg_low_temp;
float avg_precip;
int avg_wind_speed;
} weather_t;
//int loadstats(fp, weather_t ); prototype
//void printstats(weather_t wdata[]); protoyype
int main(int argc, char *argv[])
{
weather_t wdata [48];
FILE *fp;
fp=fopen("wfile.txt", "r");
for(i = 0; i < weather_t wdata; i+=4)
{
fread(&weather_t wdata [i], sizeof(int),48,fp);
}
return 0;
}
int loadstats(fp, weather_t );
void printstats(weather_t wdata[]);
Any help is appreciated