Mail Archives: djgpp/1999/07/19/08:01:08
Paul J G wrote:
:
: Hi Guys, I really need some help big time on this one, can anyone help
put
: me out of my misery ?.
: Right, I have a structure in my program:
:
: struct { float xpoint[9],float ypoint[9] } shape[10];
[snip]
: Not knowing what the varibles xpoint, ypoint, will be at compilation
time
: they must be dynamically
: allocated, as the file length for each shape could vary.
: The idea being that I can load my 3d objects into the shape varibles.
I seems you know wat you must do, dynamically allocate.
struct {
float *xpoint;
float *ypoint;
}shape[10];
now just before you assign them,
don't forget to include stdlib.h,
shape[1].xpoint = malloc(sizeof(float) * 9);
shape[1].ypoint = malloc(sizeof(float) * 9);
shape[2].xpoint = malloc(sizeof(float) * 25);
shape[2].ypoint = malloc(sizeof(float) * 25);
you should check the return of malloc in case it's null for each.
you can then shape[1].xpoint[0] = 1.345;
shape[1].xpoint[1] = 1,2353;
...
Ed
- Raw text -