Hi! I am VERY new to the programming world and am trying to complete an assignment. The assignment is as follows:
/* Purpose: Define a structure type measured_data_t with componets site_id_num (a four dig interger), wind_speed, day_of_month and temperature. Each site measures its daily data at noon. Write a program that inputs a file of measured_data_t records and determines the site with the biggest variation in temp and the site with the highest avg wind speed for the days in the input file. Data inclosed below./
/*You may assume that there will be at most ten sites */
I have been working on this thing for days and am attaching my code. The entire code must be in C. I am having trouble sorting the struct. I want to treat it as an array, but even then I'm stuck because my book only shows sorting one-dimensional array's and this looks like a 2D to me. I'm not even sure anymore!
Any tips would be appreciated!
Code:<script type="text/C"> #include <stdio.h> #include <math.h> #include <string.h> #define Max_sites 10 /* maximum number of sites allowed */ typedef struct { int site_id_num[4]; /* id number of the site */ int wind_speed[3]; /* the wind speed in knots */ int day_of_month[2]; /* the day of the month written as dd */ int temperature[2]; /* temp in celcius */ }measured_data_t; { measured_data_t current_measured, previous_measured, blank_measured = {"", 0,0,0,0} } int main(void) { /* DEFINE UNITS AND VARIABLES HERE!!!!!*/ int fscan_measured(FILE *filep, measured_data_t *measuredp); /* Fills in input data into measured_data_t * Integer returns as an indication of success or failure * With 1 => successful input of one site * and 0 => error encountered */ int fscan_measured(FILE *filep, /* input - file pointer */ measured_data_t *measuredp) /* output - measured_data_t structure to fill */ { int status; status = fscanf(filep, "%d%d%d%d", measuredp->site_id_num measuredp->wind_speed measuredp->day_of_month measuredp->temperature; if (status == 4) status =1; else if (status !=EOF) status =0; return (status); } } /* *Opens database file measured_data_t.dat and gets data to to place until end of file is encountered */ void measured_data_t[] /* output - array of data */ { FILE *inp; measured_data_t; int i, status; inp = fopen("measured_data_t.dat", "r"); i = 0; for (status = fscan_measured(inp, &data); status == 1 && i < Max_sites; status = fscan_measured(inp, &data)) { units[i++] = data } fclose(inp); /* * Compiles data and finds the average windspeed at each site ???????? */


Reply With Quote

Bookmarks