hi all,
I have a problem with linked lists.
I have written this code :
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;
}
}
Vlak and VlakList are defined like this :
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;
and G contains a pointer to a VlakList : G->vlak .
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.