CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 10 of 10

Threaded View

  1. #1
    Join Date
    Jan 2009

    Talking Newbie needing assistance!

    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!

    <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 current_measured,
    					blank_measured = {"", 0,0,0,0}
    	  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				   */
    	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
    			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
    measured_data_t[]	/* output - array of data */
    	FILE *inp;
    	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
    	 * Compiles data and finds the average windspeed at each site ????????
    Last edited by k_lynn; January 8th, 2009 at 09:05 AM. Reason: Code

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Windows Mobile Development Center

Click Here to Expand Forum to Full Width

On-Demand Webinars (sponsored)

We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.