hi all,
I have a problem with linked lists.
I have written this code :
Vlak and VlakList are defined like this :Code://in main() Vlak *vl1; vl1 = (Vlak *)malloc(sizeof(Vlak)); vl1->v1[0] = 1.0f; initVlakList(); addVlakList(vl1); ... void initVlakList(){ VlakList *v; Vlak *f, *l; v = (VlakList *)malloc(sizeof(VlakList)); f = (Vlak *)malloc(sizeof(Vlak)); l = (Vlak *)malloc(sizeof(Vlak)); v->first = f; v->last = l; G->vlak = v; } ... void addVlakList(Vlak *v){ Vlak *first, *last; first = G->vlak->first; last = G->vlak->last; if ((last == 0) && (first == 0)){ last = v; first = v; } else { last->next = v; v->prev = last; last = v; } }
and G contains a pointer to a VlakList : G->vlak .Code:typedef struct Vlak{ struct Vlak *next; struct Vlak *prev; float v1[3], v2[3], v3[3], v4[3]; }Vlak; typedef struct VlakList { struct Vlak *first; struct Vlak *last; }VlakList;
When I call this :
value = G->vlak->first->v1[0];
, it gives a wrong result (waaaaaaay to high).
Does anyone know what the problem could be ?
Thanks in advance.



LinkBack URL
About LinkBacks


