So I have tried looking for something similar to my situation but I cant find anything that helps or that is simple enough for me to understand.
My issue I am sure is not difficult, but I do not know how to do the following:
I have a structure within a structure and need to scan in multiple files into the main structure. This is what I have and the point where I am stuck is in messages. I feel as though I may need one more structure, but again I am not sure
these are my structures
typedef struct {
int year;
int month;
int day;
char time[9];
} datetime_t
typedef struct
{
datetime_t datetime;
double latitude;
double longitude;
double magnitude;
double depth;
char location[LOCATION]
} data_t
here is my scanning file
void scan_data(data_t Alaska[], data_t Central[],data_t Inner[],
data_t East[],data_t West[],data_t Canada[MAX_INFO])
{
int i=0;
FILE *FAlaska;
FILE *FCentral;
FILE *FInner;
FILE *FEast;
FILE *FWest;
FILE *FCanada;
FAlaska = fopen("Alaska.txt", "r");
FCentral = fopen("Central.txt", "r");
FInner = fopen("InnerMountain.txt", "r");
FEast = fopen("NorthEast.txt", "r");
FWest = fopen("NorthWest.txt", "r");
FCanada = fopen("NorthernCanada.txt", "r");
while (i < MAX_DATA &&
fscanf(FAlaska, "%s", data[i].datetime) !=EOF) /*here is my issue*/
{
fscanf(FAlaska, "d", data.latitude);
}
fclose(FAlaska);
return;
}
I am not sure how or if I can scan data into a structure within a structure? Do you do data[I].datetime.year? or scan into datetime as a separate array/struct and then assign it later to the bigger struct?
any help would be much appreciated on how to do this. Thank You.