I need to create large float arrays using malloc, to be able to free the memory when I don’t need the array anymore.
The values are arbitrary, meaning they are not all zeros or ones, much more random but coming from computations from another code. They can be stored in a .h file.
I first do the memory allocation (here with a small size, for commodity):
<code>float* x;
x = (float *) malloc (5 *sizeof(float)) ;
</code>
<code>float* x;
x = (float *) malloc (5 *sizeof(float)) ;
</code>
float* x;
x = (float *) malloc (5 *sizeof(float)) ;
Then I want to initialize the array with the values, such as:
<code>x = { 1.0, 2.2, 3.6, 5.4, 8.4 };
</code>
<code>x = { 1.0, 2.2, 3.6, 5.4, 8.4 };
</code>
x = { 1.0, 2.2, 3.6, 5.4, 8.4 };
But I get a compilation error:
error: cannot convert ” to ‘float*’
in assignment
What is the correct way to do this initalization?
Thanks for your help.