Hello! I'm having troubles using multidimensional arrays in my project. I will be receiving a string via serial communication that is saved to a byte-array buffer. This string of data or rather "byte-array" of data I want to save to another array. So I want an array to contain maybe 50 to 150 of these byte-arrays and they will sometimes be of different length.
Once I have saved them I want to extract them and send them to another serial port. My problem is that I don't know how to calculate the length of the different byte-arrays saved to the "main" array.
#define buffLength 260
#define arrayLength 4
byte buff[buffLength] = {0xAA, 0x40, 0x00, 0x20, 0x22};
byte buff2[buffLength] = {0xAA, 0x43, 0x02, 0x00, 0x42, 0x25, 0x48};
byte arrayOfBuff[arrayLength][buffLength] = {{0},{0}};
byte savedArrays = 2;
byte buffLen = 5;
bool hasPrinted = false;
void setup() {
Serial.begin(115200);
while(!Serial){};
Serial.println("Writing buffer to array... ");
for(int i = 0; i < savedArrays; i++){
for(int j = 0; j < buffLen; j++){
arrayOfBuff[0][i] = buff[i];
}
buffLen = 7;
}
Serial.println("done writing.");
Serial.print("The saved array is: ");
for (int i = 0; i < savedArrays; i++){
for(int j = 0; j < sizeof(arrayOfBuff[i]); j++){
Serial.print(arrayOfBuff[i][j], HEX);
}
}
}
void loop() {}
In my code I am simulating part of my full project code (which I won't post here) so that buff2 is the "buffer" getting the signal the second time after already saving it to the array. I think that I save the buffer correctly to the array but I'm not sure how I can calculate the length of each byte-array in it.