I'm working in C on an arduino project and I have the following situation:
I have 3 char arrays of different sizes, and I'd like to store the address of each of these in a fourth array.
I need these to be the address of each of the char arrays because I'd like to modify data_a, data_b, and data_c, later in the code, and have the all_data array still point to the modified arrays.
unsigned char data_a[8] = {0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07};
unsigned char data_b[3] = {0x08, 0x09, 0x0a};
unsigned char data_c[7] = {0x0b, 0x0c, 0x0d, 0x0e, 0x0f, 0x10, 0x11};
int all_data_array_length = 3;
unsigned char* all_data[all_data_array_length] = {&data_a, &data_b, &data_c};
...
/*modify the data_a, data_b, data_c arrays */
...
for(int i = 0; i<all_data_array_length; i++) {
/* do something with what all_data[i] points to /*
}
This leads to:
cannot convert 'unsigned char (*)[8]' to 'unsigned char*'
I think where I am confused is the distinction between char* and char[], and how to create a pointer to a char array.
All help is appreciated!