burkeyb 0 Newbie Poster

So my instructor gave me a 60 on this...more out of pity I'm sure....but I'm not happy with the fact that I couldn;t figure out this problem....can somebody please show me strp by step what I was doing wrong...perhaps a side by side comparison of my code compared to a code that works correctly. I knwo this is asking a lot, but I need to see where my mistakes were because I do want to learn this. FYI, do not take on-line classes for classes like this....the text is only minimly helpful at best and without an instructor to show you what is wrong, it's impossible to learn correctly. Thanks again for everybody's help.

burkeyb 0 Newbie Poster

Thanks again everybody, I have no choice but to submit what I have...it's a shame that I couldn't figure this out. Thanks again.

Keith

burkeyb 0 Newbie Poster

Thanks Narue and everybody else. Sorry to come off as such a noob but I'm only recently exposed to programming. I'm still having difficulties with this. I defined the GetInput by tellign it to open the measured_data_t file like I did in my earlier program. Somewhere along the line I have lost track...Do you see any more mistakes? I'm not trying to have you guys solve the problem for me but I'm not sure what mistakes I'm making and how to fix them....I'm trying to learn.

burkeyb 0 Newbie Poster

I thought I was implementing them....am I missing something?

burkeyb 0 Newbie Poster

Here are the errors I am getting to the code written below...I am so close but I think Im going blind from looking at this thing so much. I have started from scratch and without emulating a previous example and taking some instructor advice, I come up with the following errors.

(.text+0x34)||undefined reference to `GetInput()'

(.text+0x5f)||undefined reference to `ReadRecords(_iobuf*, SiteRecord*)'

(.text+0xa8)||undefined reference to `ProcessRecords(SiteRecord*, int, int*, int*)'

|=== Build finished: 3 errors, 0 warnings ===|

#include <stdio.h>
#include <stdlib.h>
#define NumberOfSites 10

typedef struct
{
                int site_id_num;
                int wind_speed;
                int day_of_month;
                int temperature;
}               measured_data_t;


typedef struct
{
                int site_id_num;
                int wind_speed;
                int count;
                int low;
                int high;
}               SiteRecord;

int ReadRecord (FILE* input, measured_data_t* record);
int FindRecord (SiteRecord sites[], int index, measured_data_t* record);
void InitializeRecord (SiteRecord* site, measured_data_t* record);
void UpdateRecord (SiteRecord* site, measured_data_t* record);
int ReadRecords (FILE* input, SiteRecord sites[]);
void ProcessRecords (SiteRecord site[], int sites, int* variationSite, int* windSite);
FILE* GetInput (void);

int main ()
{
                SiteRecord site [NumberOfSites];

                FILE* input = GetInput();

                if (input)
                {
                                int sites = ReadRecords (input, site);

                                fclose (input);

                                if (sites)
                                {
                                                int variationSite, windSite;

                                                ProcessRecords (site, sites, &variationSite, &windSite);

                                                printf ("\nGreatest temperature variation:  Site %d", variationSite);
                                                printf ("\nGreatest average windspeed    :  Site %d", windSite);
                                }
                }
}
burkeyb 0 Newbie Poster

I was stuck and sent my instructor what I have had so far....she gave me more advice and here is my code reworked...however I am still getting errors. Any help with this new code? Please, any help is appreciated.

#include <stdio.h>
 
#define NumberOfSites 10
 
typedef struct
{
                int site_id_num;
                int wind_speed;
                int day_of_month;
                int temperature;
}               measured_data_t;
 
 
typedef struct
{
                int site_id_num;
                int wind_speed;
                int count;
                int low;
                int high;
}   SiteRecord;    
 
int ReadRecord (FILE* input, measured_data_t* record);
int FindRecord (SiteRecord sites[], int index, measured_data_t* record);
void InitializeRecord (SiteRecord* site, measured_data_t* record);
void UpdateRecord (SiteRecord* site, measured_data_t* record);
int ReadRecords (FILE* input, SiteRecord sites[]);
void ProcessRecords (SiteRecord site[], int sites, int* variationSite, int* windSite);
FILE* GetInput (void);
 
void main (void)
{
                SiteRecord site [NumberOfSites];
 
                FILE* input = GetInput();
 
                if (input)
                {
                                int sites = ReadRecords (input, site);
 
                                fclose (input);
 
                                if (sites)
                                {
                                                int variationSite, windSite;
                                
                                                ProcessRecords (site, sites, &variationSite, &windSite);
 
                                                printf ("\nGreatest temperature variation:  Site %d", variationSite);
                                                printf ("\nGreatest average windspeed    :  Site %d", windSite);
                                }
                }
}
burkeyb 0 Newbie Poster

The problem is from my coursebook Problem Solving and Program Design in C. I am re-writing/modofying a code that was goven on a handout for the class that is "similiar" to what the original question is. I think this is why I am running into so many problems....I've tried starting from scratch using the text from the book but I can not succeed.

burkeyb 0 Newbie Poster

Thanks, for your third and fourth recommended change I am not quite sure what you are saying. Also, these are the two error messages I get when I run this

1. Line 16: error: expected unqualified-id before '{' token
2. Line 48: error: invalid function declaration

Once again thanks for your help, sorry to seem so lost but I really am on this assignment.

burkeyb 0 Newbie Poster
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

#define MAX_SITES 10 /* maximum number <strong class="highlight">of</strong> sites allowed */

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

{
/* 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", _id_num,
&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 ????????
*/
burkeyb 0 Newbie Poster

Here is the code I was working with:

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

			}
		}
           }
burkeyb 0 Newbie Poster

Please, I have tried everything that I can learn from a book...any help with this problem is greatly appreciated. I've spent days writing and modifying and I am just lost now.

Is there anybody that can help me solve this question using C language?

You are developing a database of measured meteorological data for use in weather and climate research. Define a structure type measured_data_t 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 C program that inputs a file of measured_data_t records and determines the site with the greatest variation in temperature (defined here as the 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