I want to construct a struct which has an array of unknown number of rows and 2 columns
something like
struct s
{
cinst char*** s;
}
const char* str1[][2] = {"1","2",
"3","4",
"5","6"};
s s1 = {str1};
const char* str2[][2] = {"1","2",
"3","4"};
s s2 = {str2};
The code fails in compilation.How can I solve the problem?
Aside from the typo
cinstand the missing semicolon and assuming (without letting us know)sandstruct sare the same typeyour problem is that the types of
str1and the struct membersare not compatiblestr1is of typeconst char*[][2]const char***Forcing the compiler to assume
str1is of typeconst char ***solves your immediate problem, ie, the program compiles and “works”, but you really need to understand that arrays are not pointers and pointers are not arrays. See section 6 of the c-faq site.