Hello everyone,

I am currently in a C class and I am having trouble with the following exercise. I have started but I am stuck, can anyone help?


You are developing a database of measured meteorological data for use in weather and climate research. Define a structure type measured_data_t (which I have done) with components site_id_num (a four digit integer), wind_speed, day_of_month, and temperature. Each site measures its data daily, at noon local time. Write a program that inputs a file of measured_data_t records and determines the site with the greatest variation in temperature (defined here as teh biggest difference between extrema) and the site with the highest average wind speed for all the days in the file. You may assume that there will be at most ten sites. Test the program on the following July daily data collected over one week at three sites:

ID Day Wind Speed (knots) Temperature (deg C)
2001 10 11 30
2001 11 5 22
2001 12 18 25
2001 13 16 26
2001 14 14 26
2001 15 2 25
2001 16 14 22
3345 10 8 29
3345 11 5 23
3345 12 12 23
3345 13 14 24
3345 14 10 24
3345 15 9 22
3345 16 9 20
3819 10 17 27
3819 11 20 21
3819 12 22 21
3819 13 18 22
3819 14 15 22
3819 15 9 19
3819 16 12 18

#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 ????????
	*/

			}
		}
}

The structure isn't correct, you don't have to specify the number of digits in the integers. A single integer can hold lots of digits (see limits.h in your compiler's header files).

typedef struct
	{
	int site_id_num; /* id number of the site */
	int wind_speed; /* the wind speed in knots */
	int day_of_month; /* the day of the month written as dd */
	int temperature; /* temp in celcius */
	}measured_data_t;

lines 20 and 21: It isn't necessary, nor even desireable, to put those on two different lines -- just declare the function all on one line int main() lines 36-39: you need to make those parameters pointers if you make the changes I suggested to that structure. e.g. & measuredp->site_id_num You also need to make that a loop so that it will read in all the rows in the file. Then store the data in an array of structures.

HI thanks for the input, however I'm not sure that I fully understand the changes you recommended for lines 36-39. Could you elaborate a little more and give me some examples. It doesn't have to be specific to this assignment I'm just not sure what to do.

Thanks for the help!

Well, I personally prefer to help with code that will at least compile...

Your original lines 36-39:

status = fscanf(filep, "%d%d%d%d", measuredp->site_id_num
	measuredp->wind_speed
	measuredp->day_of_month
	measuredp->temperature;

are missing the closing ')' for the function call and the ',' separating the arguments.

What dragon was referring to was that with your previous data structure, all of those parameters were arrays which made them implied pointers for the function.

If you make the changes to the data structure he recommended (and I agree with him -- no surprise there) you need to turn these into pointers here so fscanf can fill them in.

status = fscanf(filep, "%d%d%d%d", 
		&measuredp->site_id_num,
		&measuredp->wind_speed,
		&measuredp->day_of_month,
		&measuredp->temperature );

Ok, here is a modified version of the one above. What am I doing wrong as I can't get rid of the errors? (listed underneath) I'm not very good at programming as I am a retired helicopter mechanic and this class is required for my BS in Electronics Engineering Technology. Thank you for any help you guys can give me.
Respectfully,
Paul
USN Retired

#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;
	
	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
	*/
	
	

	{
	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 ????????
	*/

			}

ERRORS Received

Error 1 error C2447: '{' : missing function header (old-style formal list?)Warning 2 warning C4091: '' : ignored on left of 'int' when no variable is declared
Error 3 error C2601: 'measuredp' : local function definitions are illegal
Error 4 error C2065: 'filep' : undeclared identifier
Error 5 error C2447: '{' : missing function header (old-style formal list?)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.