Help using functions on arrays of structures

bigbearbooth's Avatar, Join Date: Dec 2007
Newbie Member
Hi everybody!

I'm new to programming and I've come across a problem when i attempt to do operations on structures.

The following line is an example:

D = (sumofweights * sum(read_data[].xsq)) - pow(sum(read_data.x), 2);

where the function sum() is supposed to sum all the members xsq in the array of a structure:

double sum(double array[]){
double result = 0;
for(int j = 0; j <= counter; ++j){ /* counter is a variable that updates everytime an . element is added to the structure */
result = result + array[j];
}
return(result);
}

I'm sure there is a syntax error in there or that I'm attempting to do something that isn't allowed, but I cannot for the life of me figure out what it is.

Any help would be very much appreciated.

Cheers,
BBB
Salem's Avatar, Join Date: Nov 2007
Ambitious contributor
Can you post the structure which is used to declare your read_data ?