I want to allocate memory dynamically using malloc
so that i can use for loop to access each array and array element.
My code looks like this:
long naxes1[3] = {1,1,1}, naxes2[3] = {1,1,1}, naxes3[3] = {1,1,1}, naxes4[3] = {1,1,1}; //upto naxes20
Another line of code is:
double *pix1, *pix2, *pix3, *pix4, *pix5; //upto *pix20
To allocate the memory, I do this:
pix1 = (double *) malloc(npixels * sizeof(double));
pix2 = (double *) malloc(npixels * sizeof(double));//20 times,
How can we use for loop to allocate memory for pixels instead of this?
moreover,
#include"cfitsio.h"
long npixels = 1;
fits_read_pix(names[0], TDOUBLE, firstpix, npixels, NULL, pix1, NULL, &status)
here, names[i] are names of fitsfile inputs, TDOUBLE is double type, first pixels, npixels, etc are local variables inside C library routine cfitsio.h