小编Gre*_*eg 的帖子

C结构中的数组

我想在一个struct中有两个数组,它们在start时初始化但需要进一步编辑.我需要三个结构实例,以便我可以索引到一个特定的结构并按我的意愿修改.可能吗?

这是我认为我可以做但我得到错误:

struct potNumber{
    int array[20] = {[0 ... 19] = 10};
    char *theName[] = {"Half-and-Half", "Almond", "Rasberry", "Vanilla", …};
} aPot[3];
Run Code Online (Sandbox Code Playgroud)

然后我按如下方式访问结构:

 printf("some statement %s", aPot[0].array[0]);
 aPot[0].theName[3];
 …
Run Code Online (Sandbox Code Playgroud)

c arrays struct

14
推荐指数
2
解决办法
8万
查看次数

标签 统计

arrays ×1

c ×1

struct ×1