This will probably do what you want, but it wasn't exactly what you asked for.
#include <stdio.h>
char *strs[] = {
"foo",
"bar",
"bazy"
};
int main() {
printf("%d - %s\n", strlen(strs[0]), strs[0]);
printf("%d - %s\n", strlen(strs[1]), strs[1]);
printf("%d - %s\n", strlen(strs[2]), strs[2]);
return 0;
}
Output:
3 - foo
3 - bar
4 - bazy
Note that you only have a few possibilities for storing arrays of arrays. You can either do what this solution does (make an array of pointers to arrays), make a "compressed" list of arrays in a large array, or make an overly large 2-D array.
The "compressed" array would take the format:
char strs[] = "foo\0bar\0bazy"; // array is {f,o,o,\0,b,a,r,\0,b,a,z,y,\0}
The problem with this format is that it's somewhat tricky to access anything after the first element, and usually involves searching linearly through the array. (or keeping a seperate table of addresses... rather like the first solution)
The 2-D array requires that you specify all sizes, and looks like this:
char strs[3][5] = {
"foo",
"baz",
"baxy"
};
int main() {
printf("%d - %s\n", strlen(strs[0]), strs[0]);
printf("%d - %s\n", strlen(strs[1]), strs[1]);
printf("%d - %s\n", strlen(strs[2]), strs[2]);
return 0;
}
This is probably laid out in memory like this:
{f,o,o,\0,*,b,a,z,\0,*,b,a,x,y,\0} (the *'s could be anything, most dependent on your compiler)
Since the compiler knows that each string takes exactly 5 bytes, it can easily calculate the location of the later elements.