This is my external function
Code:
double *splitme(double *array, size_t p, size_t q)
{
int i, n, j;
double sum1, sum2;
double *bfun_split;
size_t array_size, centroid;
//cast centroid as size_t
//round centroid sum
//q is centroid -1
//p is length - centroid - 1
//allocate new array double centroidedarray length same as before
//from 0 to p allocate everything from the right of centroid
//from length-q-1 till end allocate left of centroid
//free old
//return new
array_size = p;
for (i=0; i<array_size; i++)
{
sum1 += (i * array[i]);
sum2 += array[i];
}
centroid = (round)(sum1/sum2);
printf("centroid is %d\n", centroid);
q = centroid - 1;
p = array_size - centroid - 1;
printf("array size is %i\n", array_size);
printf("p is %i\n", p);
printf("q is %i\n", q);
bfun_split = malloc((array_size)*sizeof(double));
i=0;
for (i=0; i<p; i++)
{
bfun_split[i] = array[i+centroid];//allocate the right of the centroid
}
i=0;
//x=(array_size - q - 1);
for (i=(array_size - q - 1); i<array_size; i++)
{
bfun_split[i] = array[i-centroid]; //allocate the left of centroid
}
i=0;
for (i=0; i<array_size; i++)
{
printf("split array %i is %lf\n", i, bfun_split[i]);
}
return(*array);
free(array);
}
and this is my call
Code:
*split_array= *splitme(bfun_array, bfun_lines, 0);
When compiling it wont let me put return(*array) only return(array) and I was under the impression that in order to return an array it had to be a pointer?