您好,我在定义结构中的结构数组时遇到了一些麻烦。 这是我的想法,我需要一个名为figure的结构,它包含图形的名称,坐标计数和坐标(x,y)。每个图可以有任意数量的坐标。 我还需要能够动态地重新分配空间以获得不断增加的坐标列表......请帮助指引我朝着正确的方向前进。 谢谢你,在C中定义一个结构中的结构阵列C
泰勒
typedef struct {
char fig_name[FIGURE_LEN + 1];
int coordcount;
/* here i need to declare an array of coord structures that
but i am not sure how to do this properly. I was originally
going to try something like as follows */
coords *pointer;
pointer = malloc(sizeof(coords));
pointer = coords figcoord[];
/* however i am quite certain that this would not work */
} figure;
typedef struct {
double x;
double y;
} coords;
您不能将默认结构值分配给C中的成员变量。您的* code *隐藏在结构定义的中间。在可以使用之前,必须先声明坐标,否则不会在C. – WhozCraig
中工作。另外,C是一种静态类型语言,因此您需要先声明才能进行分配。 – yeyo
@Kira是的,我认为这是一个问题,我只是不知道如何解决这个问题。 – wenincode