gpt4 book ai didi

c - 在另一个结构中初始化结构值

转载 作者:太空宇宙 更新时间:2023-11-03 23:49:30 25 4
gpt4 key购买 nike

我正在尝试通过以下代码使用另一个结构将值初始化为一个结构:

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
解决这个问题的方法是什么?

最佳答案

您在第一个结构中有错误。我假设您是用 C 编写的。C 没有结构成员的默认值。

完美编译:

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 }
};

关于c - 在另一个结构中初始化结构值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24035403/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com