Pointer giving me rubbish in C although correct in another function -


so have list:

struct list_elem {     char* key;     void* value;     struct list_elem *prev;     struct list_elem *next; }; 

and when try @ key , value of 2 different functions use same code try , see values are, 1 gives me correct answer , 1 doesnt.

i add elements list :

xpoint xpts[npts + 1];  ...do stuff ...  xpoint *pointr = (xpoint*) calloc(npts, sizeof(xpoint)); pointr = &xpts; list_insert(&w->qr_coord, data, pointr);  

i try , key , value in 1 function (functiona):

void list_insert(struct list *list, char* key, const void *value) {      struct list_elem *elem = list_start(list);      while (has_next(elem)) {         xpoint pointr = (xpoint*) elem->value;         printf("%s\n", elem->key);                           //this right         printf("(%i,%i)\n", pointr->x, pointr->y);           //this right          //more code     } } 

and in function(functionb) this:

struct list *qr_list = &proc->window->qr_list; struct list_elem *elem = list_start(qr_list); xpoint pointr = (xpoint*) elem->value; printf("%s\n", elem->key);                             //this comes out right printf("(%i,%i)\n", pointr->x, pointr->y);             //this wrong 

the wrong answers gives me random numbers 0, 2345, -129953. im not sure why not working anymore advice appreciated.

cheers

i guess should be

*pointr = xpts[...]; 

instead of

pointr = &xpts; 

the current code doesn't use memory you'va allocated stores address of xpts. , if that's local variable, address invalid. if xpts global, &xptr type xpoint **, not xpoint *


Comments

Popular posts from this blog

php - get table cell data from and place a copy in another table -

javascript - Mootools wait with Fx.Morph start -

php - Navigate throught databse rows -