Dear users,
Can anyone tell me what formula I
can use to referenciate one 2-D array
element dynamically allocated?
Example:
...
#include <stdlib.h>
...
int main()
{
double *2d_array; /* I want to use a 3-row 2-column 2-D array */
2d_array = (double *) malloc(3*2*sizeof(double));
/*
2d_array[0][0] 2d_array[0][1]
2d_array[1][0] 2d_array[1][1]
2d_array[2][0] 2d_array[2][1]
becomes:
*(2d_array+0), *(2d_array+1), *(2d_array+2), *(2d_array+3),
*(2d_array+4), *(2d_array+5)
*/
...
/*
I need to find a way to do assignments like this:
2d_array[2][1] = 4.0;
but I need to do it by a GENERIC (for every MxN 2-D array,
not just for a 3x2) linear combination of
the indexes, something like *(2d_array + 5) = 4.0;
*/
}
Any ideas?
Regards
Andre
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.5.488 / Virus Database: 269.13.28/1023 - Release Date: 22/9/2007
13:27
|