This seems like a question that should have been answered already somewhere but I can’t seem to find something satisfactory. Anyway I need to return from a function something that looks like:
{ {"foo", "bar"}, {"baz", "foo"}, {"foo", "bar"} }
I am familiar with the use of argv and I understand what its types means but for some reason I can’t get the type of the above expression correct. There will always be 2 string literals on the innermost part and as such I thought something like either
char **s[2] or char *(*s[2])
should be what I am after but for some reason I constantly end up with a segfault no matter the permutation I try when I attempt to iterate through and use printf. Also the compiler is constantly complaining about incompatible pointer types, excess elements and too many braces. This is the current code:
char *(*s[2]) = { {"foo", "bar"}, {"baz", "spam"}, {"eggs", "ham"} };
You are close.
The above prints:
foo bar baz spam eggs ham