home *** CD-ROM | disk | FTP | other *** search
- //• MacArrayTrickery.c - corrected THINK C version
- //• Dynamically create multidimensional arrays in C.
- //• From TrickyS@aol.com, aka meidscsinc@engvms.unl.edu
- //• Inspired by AFC Radix1@aol.com, MCart@aol.com, &RickGenter@aol.com,
- //• who all answered my inquiry as to how to do this!
- //• Updated for Squeegee.
- //• This version works on the MAC using THINK Cv6.
-
- /* As a final note, I would encourage anybody programming
- seriously in C to buy a copy of the text "Numerical Recipes in C".
- This book provides a wealth of utility functions, numerical and otherwise.
- Best of all, THEY WORK!
- */
-
- /* I replaced the <= with < to avoid overstepping
- array bounds. Sorry about that! */
-
- #include <Memory.h>
-
- main()
- {
- float ***array;
- short x=3, y=4, z=5, i, j, k;
-
- array = (float***)NewPtr(x*sizeof(float**));
- for(i=0; i<x; i++)
- {
- array[i] = (float**)NewPtr(y*sizeof(float*));
- for(j=0; j<y; j++)
- {
- array[i][j] = (float*)NewPtr(z*sizeof(float));
- for(k=0; k<z; k++)
- array[i][j][k] = i+j+k;
- }
- }
- //• No output produced, but it works. Run it with the Debugger on
- //• to see for yourself that it is really working!
- return 0;
- }
-