I'm new to C Programming ( 6th week of an 8 week course ) and I am working on user defined structures. I have created a structure to store data received from a file and three of the four sub functions planned: open the file, store the data in the file (with error control measures), and determine the maximum variation in temperature. In the code I am posting, I have not created the MAIN function yet. I am strictly working on the sub-functions at this time. I am getting the error "expected identifier before ',' token on lines 19 and 83. Can someone show me (explain to me in layman's terms) my error in this function prototype and call? The highlighted function is supposed to pull data from the structure, create a local array to store calculated information, compare the "id" field in the structure (for control purposes) and then calculate the maximum variation for temperatures associated with that ID. If the ID does not match, then the current minimum value of temperatures is subtracted from the maximum value of temperatures stored in the correct array position along with the ID. Once the entire structure is gone through, the values of the ID and maximum variance are to be returned to the main function (which isn't created yet).
/*
* Program pulls data from a text file, determines maximum temperature variation and
* highest average wind speed between several locations using user created structured
* data types.
*/
#include <stdio.h>
typedef struct
{
int id; // 4 digit ID is used to track location for calculations
int day; // 2 digit numerical day of month
int ws; // ws is the wind speed in knots
int temperature;// daily temperature measurement
} measured_data_t;
int fscan_data(FILE *filep, measured_data_t *unitp);
void load_data(int data_max, measured_data_t data[], int *data_sizep);
int max_temp(measured_data_t id, measured_data_t temperature, , int *ID, int *max_temp);
// insert declaration of function to get max temp variation
// insert declaration of function to get highest average windspeed
/*
* Gets data from a file to fill output arguments
* Returns standard error code: 1=> successful input, 0 => error, negative EOF value => EOF
*/
int
fscan_data(FILE *filep, measured_data_t *unitp)
{
int status;
status = fscanf(filep, "%d%d%d%d", unitp->id,
unitp->day,
unitp->ws,
unitp->temperature);
if (status == 4)
status = 1;
else if (status != EOF)
status = 0;
return (status);
}
/* Opens file weather_data.txt and gets data to place in data until EOF is found.
* stops early if there are more than unit_max data or invalid data.
*/
void
load_data( int data_max, measured_data_t data[], int *data_sizep)
{
FILE *inp;
measured_data_t data_in;
int i, status;
// Gets info from file
inp = fopen("weather_data.txt", "r");
i = 0;
for (status = fscan_data(inp, &data_in);
status == 1 && i < data_max;
status = fscan_data(inp, &data_in))
{
data[i++] = data_in;
}
fclose(inp);
// Error message for early exit
if (status == 0)
{
printf("\n***** Error in data format in txt file *****\n");
printf("***** Using the first %d data values *****\n", i);
}
else if (status != EOF)
{
printf("\n***** Error file contains too many sites *****\n");
printf("\n***** Using first %d data values *****\n", i);
}
// Return the size of the used portion of the array
*data_sizep = i;
}
/* Calculates max temperature variation for sites and returns the ID and max_temp to main */
int
max_temp(measured_data_t id, measured_data_t temperature, , int *ID, int *max_temp);
{
int ID[], MAX_VAR[]; // Array to store the Maximum variation in temperature with its ID
int max_temp = 0; // Set to zero so it will increase
int min_temp = 100; // Temp is air temp in degrees C, so set to above max expected
int big_val;
if(measured_data_t.id == ++measured_data_t.id)
{
if (measured_data_t.temperature < min_temp)
min_temp = measured_data_t.temperature;
if (measured_data_t.temperature > max_temp)
max_temp = measured_data_t.temperature;
}
else if(measured_data_t.id != EOF)
{
max_tem_var = (max_temp - min_temp);
ID[i] = measured_data_t.id;
MAX_T[i] = (max_temp_var);
++i;
}
else if(measured_data_t.id == EOF)
{
for(i=0; i<sizeof(MAX_T); i++;)
{
if (big_val < MAX_T[i])
{
big_val = MAX_T[i]
return(ID[i], max_temp[i]);
}
}
}
}
// insert main
I may be seriously over thinking the third structure, but once I get the function to work, create the fourth function, and the main, I will work on my logic errors. Right now I am focused simply on the error regarding the "expected identifier". I am going to start work on the fourth function while waiting on advice, but I assume that I will probably have the same error in calling that function since it works with the same data except it calls "ws" (wind speed) from the structure instead of temperature.