Hi there I am having a bit of trouble with defining an array of structures within a structure.
This is my idea, I need to have a structure called figure which holds the name of the figure, coordinate count and the coordinates (x,y). Each figure can have an arbitrary amount of coordinates.
I also need to be able to dynamically reallocate space for an ever increasing list of coords… Please help point me in the right direction.
thank you,
tyler
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;
Kick toward the right direction. Try something like this. I apologize for the lack of error checking for the
malloc()calls, but you will get the general idea (I hope):