The following code works perfectly well if I put the function content into the main block, but the function completely fails here. I currently get a 'subscripted value is neither array nor pointer nor vector' error. I also get 'passing argument 1 and 4 of 'accumulate' from incompatible pointer type' errors.
void accumulate( double sum[], int ypos[], int xpos[], int vals[], int numvals )
{
for(int i=0 ; i<numvals ; i++) /// start looping over indices
{
sum[ypos[i]][xpos[i]] += vals[i];
}
}
int main()
{
int xpos[2] = {0,1};
int ypos[2] = {0,1};
double vals[2] = {1.01,7};
int numvals = 2;
int size = 6;
double sum[size][size];
for(int i=0; i<size ;i++)
{
for(int j=0; j<size ; j++)
{
sum[i][j] = 0; // make zeros
}
}
accumulate(sum,ypos,xpos,vals,numvals); // doesn't work
for(int i=0; i<size ;i++)
{
for(int j=0; j<size ; j++)
{
printf("%f ", sum[i][j]);
}
printf("\n");
}
}
sumvariable last in theaccumulate()call like thisaccumulate(ypos,xpos,vals,numvals, sum);. 2.) Try sending the address of the array instead of a copy of the array like thisaccumulate(ypos,xpos,vals,numvals, &sum);that should perform changes on the original array and not on a copy. 3.) Try writing the declaration of theaccumulatefunction asvoid accumulate( ..., double sum[][]);- Ivan86cso I'm not fluent currently. - Ivan86