我试图通过以下代码使用其他结构将值初始化为结构:
struct freq
{
char temp[20];
int count=0;
};
struct test
{
char input[100];
struct freq words[20];
int len;
}testdb[1] =
{
{ "ram is playing.he likes playing", { { "ram", 1 }, { "is", 1 }, {"playing", 2 }, { "he", 1 }, { "like", 1 } }, 5 }
};
但是我收到的错误无法从initializer
列表转换为freq
这是什么解决方案?
答案 0 :(得分:1)
第一个结构中有错误。我假设你是用C语言编写的.C没有struct成员的默认值。
这完美编译:
struct freq
{
char temp[20];
int count;
};
struct test
{
char input[100];
struct freq words[20];
int len;
}testdb[1] =
{
{ "ram is playing.he likes playing", { { "ram", 1 }, { "is", 1 }, {"playing", 2 }, { "he", 1 }, { "like", 1 } }, 5 }
};