If you want to make an array of arrays of different sizes, you need to make an array of pointers, like this:
char *myArrays[] = {
(char[]){'a','b','c'},
(char[]){'a'},
(char[]){'a','d'}
};
You do not need to "pad" your arrays with null characters.
Note that this approach does not provide an easy way of finding out the exact length of inner arrays: sizeof
operator is not going to work. If you want to know the lengths of the inner arrays, either add terminating entries of some sort (say, '\0'
s) or add an array of lengths, like this:
size_t myLengths[] = {3, 1, 2};
Now you can iterate the array of arrays like this:
for (int i = 0 ; i != 3 ; i++) {
for (int j = 0 ; j != myLengths[i] ; j++) {
putchar(myArrays[i][j]);
}
putchar('\n');
}
Demo on ideone.