I have simple struct:
typedef struct{
double par[4];
}struct_type;
I have also initialize function for it where one argument is a 4 elements array. How properly use memcpy to initalize array in struct? Something like this don't work for me:
struct_type* init_fcn(double array[4]){
struct _type* retVal;
retVal->par=malloc(sizeof(double)*4);
memcpy(retVal->par,&array);
return retVal;
}
I can init values one by one but i thnik memcpy will be better and faster. Do You have any ideas how to proper do it?
sizeof(*double)is nonsense and will result in a compiler error. This isn't a minimal reproducible examplememcpy(retVal->par, array, sizeof(double)*4). Also in malloc you usesizeof(double)(size of one element)*) located?