Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You're being passed a pointer to a pointer. You want to alter the pointer that is being pointed to, not the pointer to a pointer itself. Does that make sense?</p> <pre><code>if(lst == NULL) </code></pre> <p>Here you're checking to see if you were passed a NULL pointer. Good practice for error checking, but not for what you were doing right there. If <code>lst</code> is NULL, then you don't even have a pointer to a pointer, can't do anything, and should return a nonzero error code without doing anything else.</p> <p>Once you're sure your pointer is not NULL, <em>then</em> you look at the pointer it's pointing to (<code>*lst</code>). The pointed-to pointer is the pointer to the first list item. If <em>that</em> pointer is NULL, <em>then</em> you change it to the new item's pointer. Basically, where you use <code>lst</code> you should be using <code>*lst</code> or <code>(*lst)</code>. (REMEMBER: the <code>*</code> operator runs <em>after</em> the <code>-&gt;</code> operator! So to get a field in the object pointed to by the pointer that is pointed to by <code>lst</code> [pant, pant], you use <code>(*lst)-&gt;whatever</code>.)</p> <p>P.S. This kind of pointer work is <em>critical</em> to learn to be a good programmer, especially with C.</p> <p>P.P.S. The other thing you got wrong is that instead of</p> <pre><code>insert_intlist(lst, i); </code></pre> <p>you're supposed to call it like</p> <pre><code>insert_intlist(&amp;lst, i); </code></pre> <p>... and, for brownie points, check the return code for errors.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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