Note that there are some explanatory texts on larger screens.

plurals
  1. POPointer giving me rubbish in C although correct in another function
    text
    copied!<p>So I have a list: </p> <pre><code>struct list_elem { char* key; void* value; struct list_elem *prev; struct list_elem *next; }; </code></pre> <p>And when I try to look at the key and value of it from two different functions but use the same code to try and see what the values are, one gives me the correct answer and one doesnt. </p> <p>I add elements to my list like this : </p> <pre><code>XPoint xpts[npts + 1]; ...do stuff ... XPoint *pointr = (XPoint*) calloc(npts, sizeof(XPoint)); pointr = &amp;xpts; list_insert(&amp;w-&gt;qr_coord, data, pointr); </code></pre> <p>I then try and get the key and value like this in one function (FunctionA):</p> <pre><code>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-&gt;value; printf("%s\n", elem-&gt;key); //THIS IS RIGHT printf("(%i,%i)\n", pointr-&gt;x, pointr-&gt;y); //THIS IS RIGHT //more code } } </code></pre> <p>And in another function(FunctionB) I do this:</p> <pre><code>struct list *qr_list = &amp;proc-&gt;window-&gt;qr_list; struct list_elem *elem = list_start(qr_list); XPoint pointr = (XPoint*) elem-&gt;value; printf("%s\n", elem-&gt;key); //THIS COMES OUT RIGHT printf("(%i,%i)\n", pointr-&gt;x, pointr-&gt;y); //THIS IS WRONG </code></pre> <p>The wrong answers gives me random numbers like 0, 2345, -129953. Im honestly not sure why it is not working anymore any advice would be appreciated.</p> <p>Cheers </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload