#3D Jagged Array

3 messages · Page 1 of 1 (latest)

dawn spruce
#

Hey. How would I go about creating a 3D jagged array in C that's dynamically allocated? I've created a 2D dynamically allocated jagged array so I'm guessing it shouldn't be too different.

This is my thought process:

some_struct ***ptr;
int *size1 // keeps track of how many ptr[i]
int *size2 // keeps track of how many ptr[i][j]

Allocate memory for size1 and allocate memory for ptr based on some value (say 3) 

for i 0 -> 5
   Allocate memory for ptr[i]
Allocate memory for size2 (5)

for i 0 -> 5
    for j 0 -> 4 
        Allocate memory for ptr[i][j]

... do stuff with ptr
fringe prairieBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

gray tide
#

(OP left server)