#include #include #include #define WFILE "temps.txt" typedef struct { char time[10]; char ampm[2]; } Time; void timePrinter(char* target, Time* time) { sprintf(target, "%s %s", time->time, time->ampm); } typedef struct { char direction[10]; int speed; char scale[4]; } Wind; typedef struct { int temperature; char scale[2]; } Temperature; typedef struct { Time time; Temperature temperature; Temperature dewPoint; int relHum; Wind wind; } WeatherData; WeatherData weather[100]; void wprinter(WeatherData* w) { printf("Time:%s %s Temp:%d %s\n", w->time.time, w->time.ampm, w->temperature.temperature, w->temperature.scale); } void wprinterB(WeatherData* w) { char timee[15]; timePrinter(timee, &w->time); printf("Time:%s Temp:%d %s\n", timee, w->temperature.temperature, w->temperature.scale); } WeatherData parseB(char* line) { WeatherData w; char* c = strtok(line, " \t"); strcpy(w.time.time, c); c = strtok(NULL, " \t"); printf("%s\n", c); strcpy(w.time.ampm, c); c = strtok(NULL, " \t"); w.temperature.temperature = (int)strtol(c, NULL, 10); c = strtok(NULL, " \t"); strcpy(w.temperature.scale, c); c = strtok(NULL, " \t"); w.dewPoint.temperature = (int)strtol(c, NULL, 10); c = strtok(NULL, " \t"); strcpy(w.dewPoint.scale, c); c = strtok(NULL, " \t"); w.relHum = (int)strtol(c, NULL, 10); c = strtok(NULL, " \t"); strcpy(w.wind.direction, c); c = strtok(NULL, " \t"); w.wind.speed = (int)strtol(c, NULL, 10); c = strtok(NULL, " \t"); strcpy(w.wind.scale, c); return w; } int main(void) { char line[256]; FILE* f = fopen(WFILE, "r"); if (f==NULL) { fprintf(stderr, "Could not open %s -- quitting\n", WFILE); return 1; } int c = 0; while (NULL != fgets(line, 256, f)) { weather[c] = parseB(line); c++; } for (int i=0; i