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
};
正如您在代码中看到的,我想创建一个静态分配但动态大小的数组。我知道如何遍历数据,只是编译器在声明时出错了。当我在寻找 C 解决方案时,还有 C++ 的奖励积分。
谢谢!