typedef struct DictionaryEntry_s {
char *key;
char *value;
} DictionaryEntry;
typedef struct Dictionary_s {
char *name;
DictionaryEntry values[0];
} Dictionary;
//How can I do the following:
Dictionary myDictionary[] = {
{"synonyms",
{"good", "cool"},
{"bad", "evil"},
{"awesome", "me"},
{"like", "love"}, //etc....
{0} //terminator
},
{"antonyms",
{"good", "evil"},
{"bad", "good"},
{"awesome", "not me"}, ///...etc
{0} //terminator
},
{0} //terminator
};
As you can see in the code, I want to create a statically allocated but dynamically sized array. I know how to loop through the data, its just that the compiler barfs at the declaration. While I am looking for a C solution, bonus points for C++ in addition.
Thanks!
C solution requires extra variables for defining internal arrays:
C++ solution – requires
std::vector<>– however it is notstaticallyallocated, but dynamically, and it does not requires terminator: