#include #include #include #include "WeatherDataSel.h" int tempComparator(const void *p, const void *q) { WeatherData* pw = (WeatherData*)p; WeatherData* qw = (WeatherData*)q; return pw->temperature.temperature - qw->temperature.temperature; } void timePrinter(char* target, Time* time) { sprintf(target, "%s %s", time->time, time->ampm); } 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 DewPt:%d %s\n", timee, w->temperature.temperature, w->temperature.scale, w->dewPoint.temperature, w->dewPoint.scale); } char* strmcopy(char* src) { char* newstr = malloc((strlen(src)+1)*sizeof(char)); strcpy(newstr, src); return newstr; } void wfree(WeatherData* wc) { free(wc->time.time); free(wc->time.ampm); free(wc->temperature.scale); free(wc->dewPoint.scale); free(wc->wind.direction); free(wc->wind.scale); } WeatherData* parseB(char* line) { WeatherData* wp = malloc(sizeof(WeatherData)); char* c = strtok(line, " \t"); wp->time.time = strmcopy(c); c = strtok(NULL, " \t"); wp->time.ampm = strmcopy(c); c = strtok(NULL, " \t"); wp->temperature.temperature = (int)strtol(c, NULL, 10); c = strtok(NULL, " \t"); wp->temperature.scale=strmcopy(c); c = strtok(NULL, " \t"); wp->dewPoint.temperature = (int)strtol(c, NULL, 10); c = strtok(NULL, " \t"); wp->dewPoint.scale=strmcopy(c); c = strtok(NULL, " \t"); wp->relHum = (int)strtol(c, NULL, 10); c = strtok(NULL, " \t"); wp->wind.direction = strmcopy(c); c = strtok(NULL, " \t"); wp->wind.speed = (int)strtol(c, NULL, 10); c = strtok(NULL, " \t"); wp->wind.scale = strmcopy(c); return wp; }