MultiDimensonal Array; Dynamic in one dimension.

Hello.

I am trying to create a dynamic 2D array.

I have seven zones which i am trying to fill with a selected pattern, whose size is dynamically generated depending on how "large" the each of the zones. The pattern depends on the size of the zone.

I know the first dimension of the array, but not the second.

byte hueArray[7][??];


byte *hueArray = (byte *)malloc(patternLength * sizeof(byte));

I've been using this to generator a dynamically sized single array.... but now that i am adding zones, i need to do this for each zone.

even something like

byte *hueArray1 = (byte *)malloc(patternLength * sizeof(byte));
byte *hueArray2 = (byte *)malloc(patternLength * sizeof(byte));
byte *hueArray3 = (byte *)malloc(patternLength * sizeof(byte));

would work, assuming later on in the program i could some how select which array to read and write without needing a whole lot of switch/case statements.

eg,

for(int i = PatternStart; i < PatternEnd; i++){
hueArray[ZONE][i] = value;
}

I have also posted my code. The problems are in the "LEDprgrams" tab and subsequent pattern functions, "ZA"-"ZK". Be warned, its a lot of code.

Archive.zip (17.5 KB)

I did not look at your code.

byte *hueArray[7];

Seven pointers to dynamically allocated byte arrays.

Simple example

  for (int cnt = 0; cnt < 7; cnt++)
  {
    hueArray[cnt] = (byte*)malloc(10);
  }

Not added: check if malloc() was successful.

PS
Please post your code snippet using code tags.

hmm. i had that thought but i was unsure how to call the array when i want to write to to.

would it be

hueArray[1][27]  = 27  //set the 28th byte of the second array equal to 27

thanks.

Try it in a small sample code :wink: