I can convert it if the doulble * is pointing only to one double but not an array.
Here is my function,
double fun(double * in){
return *in;
}
My double * in
has 9 elements and I'm trying to pass them to an array out[9]
;
I can convert it if the doulble * is pointing only to one double but not an array.
Here is my function,
double fun(double * in){
return *in;
}
My double * in
has 9 elements and I'm trying to pass them to an array out[9]
;
You cannot return an array, you need to declare it outside the function:
void fun(double *out, double *in, size_t num_items){
int i;
for (i = 0; i < num_items; i++) {
out[i] = in[i];
}
}
// Somewhere else in your code:
double destination[9];
fun(destination, in, 9); // Copy 9 doubles into destination
#include <stdio.h>
#include <string.h>
typedef struct dbl9 {
double array[9];
} Dbl9;
Dbl9 fun(double *in){
Dbl9 ret;
memcpy(ret.array, in, sizeof(ret.array));//There can be no assurance that <in> the correct
return ret;
}
int main(){
double array[9] = {1.0, 2.0, 3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0};
Dbl9 dbl9= fun(array);
int i;
for(i=0;i<9;++i){
printf("%f\n", dbl9.array[i]);
}
return 0;
}