Help using functions on arrays of structures

Discussion in 'C' started by bigbearbooth, Dec 4, 2007.

  1. bigbearbooth

    bigbearbooth New Member

    Joined:
    Dec 4, 2007
    Messages:
    1
    Likes Received:
    0
    Trophy Points:
    0
    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 :)
     
  2. Salem

    Salem New Member

    Joined:
    Nov 15, 2007
    Messages:
    133
    Likes Received:
    5
    Trophy Points:
    0
    Occupation:
    Please don't PM me for 1:1 support.
    Can you post the structure which is used to declare your read_data ?
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice