Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   Help using functions on arrays of structures (http://www.go4expert.com/forums/help-using-functions-arrays-structures-t7708/)

bigbearbooth 4Dec2007 23:02

Help using functions on arrays of structures
 
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 5Dec2007 12:22

Re: Help using functions on arrays of structures
 
Can you post the structure which is used to declare your read_data ?


All times are GMT +5.5. The time now is 19:34.