gpt4 book ai didi

c - 将结构保存在 C 中的数据库文件中

转载 作者:搜寻专家 更新时间:2023-10-30 22:17:25 25 4
gpt4 key购买 nike

我想将一个结构保存到一个 db 文件(或 .txt,这仍然无关紧要!),但我遇到了以下问题。我想在结构内部创建结构,如下面的代码。

typedef struct classes cl;
typedef struct attribute a;

struct classes{ \\where "a" is a type of struct
a hunter;
a channeler;
a warrior;
a rogue; };


struct human{ \\where "cl" is type of struct classes (
cl Borderlands;
cl Shienear;
cl Arafel;
cl Illian;
cl Tear;
cl Tarabon;
cl Andor;
cl TwoRivers;
cl Amandor;
cl Mayene;
cl Murandy;
};

问题是我是否有一个变量 构造人类数据我是否必须保存树的所有分支(因为我认为它是我创建的树),或者仅通过保 stub 来保存整个结构?

附言请原谅我的写作方式,我没有编程经验

最佳答案

你应该像这样为每个结构创建保存方法:

void save_h(human * h, FILE * stream)
{
save_cl(h->Borderlands,stream);
save_cl(h->Shienear,stream);
save_cl(h->Arafel,stream);
save_cl(h->Illian,stream);
save_cl(h->Tear,stream);
save_cl(h->Tarabon,stream);
...
}

void save_cl(classes * cl, FILE * stream)
{
save_a(cl->hunter,stream);
save_a(cl->channeler,stream);
save_a(cl->warrior,stream);
save_a(cl->rogueon,stream);
...
}

void save_a(attribute * a, FILE * stream)
{
...
}

关于c - 将结构保存在 C 中的数据库文件中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9669189/

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