My problem should be fairly simple, but I can't seem to find a place where this is done in the exact manner I am doing it, or at least nowhere that I can adapt to this.
The idea here is to declare a char pointer, then using realloc, expand it into an array that I can then assign pointers that point to the starting character of an array.
From what I've read before, I should be able to just access it as if it were a two-dimensional array, but when I try the following code, I get an error: Invalid indirection in function main when I try to use printf.
#include <stdio.h>
char *testArr;
unsigned char arr1[5] = {10, 20, 30, 40, 50};
unsigned char arr2[7] = {1, 2, 3, 4, 5, 6, 7};
unsigned char arr3[3] = {50, 150, 200};
int main(void){
realloc(testArr, sizeof(testArr) + sizeof(char *));
realloc(testArr, sizeof(testArr) + sizeof(char *));
testArr[0] = &arr1;
testArr[1] = &arr2;
testArr[2] = &arr3;
printf("%i", *testArr[0][3]);
getchar();
return 0;
}
I've tried a few things, including removing &'s from the assignment of the values into the pointer array, but I am honestly at a loss here. Perhaps someone with better C experience can help me here. Thanks.
realloc()3 times with the same arguments?sizeof(testArr)is going to change? It's the size of a pointer.