Groovy hepcat Nick Keighley was jivin' on 15 Mar 2007 08:28:01 -0700
in comp.lang.c.
Re: dynamic 2 D array with malloc??'s a cool scene! Dig it!
i am trying to create a dynamic 2D array with size N x 3 (N will be
put in as a parameter) using the following code:
int **xyz;
int i,N;
by convention uppercase is reserved for macros.
N=30000;
xyz=malloc(3*sizeof(int*));
since 3 is fixed you could do
int *xyz[3];
Or rather, since it's supposed to be N x 3, not 3 x N
int (*xyz)[3];
....
xyz = malloc(N * sizeof *xyz);
....
Then the whole thing is allocated in one shot, used as a 2D array
(except when the operand of & or sizeof) and, when finished, freed in
one shot.
--
Dig the even newer still, yet more improved, sig!
http://alphalink.com.au/~phaywood/
"Ain't I'm a dog?" - Ronny Self, Ain't I'm a Dog, written by G. Sherry & W. Walker.
I know it's not "technically correct" English; but since when was rock & roll "technically correct"?