Coder's Guild Mailing List

Re: Dynamic 2d arrays

Posted by pontingdavid@xxx.xxx on 2000-04-26

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On Wed, 26 Apr 2000, Eian wrote:
> 2 dimensional array 100x100:
> 
> int twoD[100][100];
> 
> 3 dimensional array 20x50x100:
> 
> int threeD[20][50][100];
> 
> etc. etc. Very easy really. :) Enjoy!
> 
> Eian
> 
Errr.... That's not dynamically allocated. Dynamic allocation is when you
allocate the appropriate memory for an array based on values learned later
in the program, e.g.

int *i, a, Depth;
.
.
~~get Depth from somewhere
.
i = (int *)malloc(Depth*sizeof(int));
for(a=0;a<27;a++){
   i[a]=a;
}
for(a=0;a<27;a++){
   printf("%d\n", i[a]);
}
free(i);

I can do a 1d array in this way, but it doesn't work for 2d. Thanks again,

 -Dave Ponting <pontingdavid@xxx.xxx>

"If ignorance is bliss, why aren't   -o)
      there more happy people?"       /\
                          -Anon      _\_v


-----BEGIN PGP SIGNATURE-----
Version: PGP 6.5.1i
Charset: cp850

iQA/AwUBOQbELmUEHPY27/15EQI1HwCghRPKdRc2pS60p39b2lOu5PIDNBYAn3E0
OJhTZgmTlaOXZrRgQrMIQdcj
=/pOR
-----END PGP SIGNATURE