Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Lots of issues here...</p> <p>1) Your price variable <code>int price;</code> is of type "int". Meaning a numeric whole value (no decimal point). Yet when you assign to it you do this:</p> <pre><code>first_train-&gt;price = 129.99; // &lt;-- wrong, the .99 isn't going to work there </code></pre> <p>And this:</p> <pre><code>second_train -&gt;price = '69.99'; // &lt;-- wrong... just.. wrong. </code></pre> <p>You'll need to use a double or float if you want these to be number values with a fractional part, or you'll have to use a string if you're not doing math on them</p> <p>2) The second problem is you're trying to use single quotes for strings. <code>'</code> is used for a single character, like <code>'a'</code>, double quotes <code>"</code> are used for strings, such as <code>"an apple"</code></p> <p>So if you want prices to be a string you need "69.99", and your names should be the same "Uncle Bobs train set"</p> <p>3) This is not how you assign a string:</p> <pre><code>third_train -&gt;name = 'Budha Bread Train'; </code></pre> <p>You need to use <code>strcpy()</code> or <code>memcpy()</code> or a function to copy the data into the string. </p> <p>4) Your list is not "linked". You need to point "next" to the next item in your list, right now you just have four independent structures. If you think of a structure in memory like a "block", something like this:</p> <p><img src="https://i.stack.imgur.com/v1R4g.jpg" alt="enter image description here"></p> <p>So you could generate this with the code you have. You have three independent structures, you can access them by <code>first_train-&gt;price</code> for example. But they are just that. Three unlinked structures. The "linked" part comes in with those next pointers. You need to "point" each next pointer to the next node, like this:</p> <pre><code>root-&gt;next = first_train; first_train-&gt;next = second_train; </code></pre> <p>by doing that you're "connecting" the structures, you can think of it like this:</p> <p><img src="https://i.stack.imgur.com/tbNDL.jpg" alt="enter image description here"></p> <p>If they were linked like this, if I had just one node (the root) I could access anyone's data:</p> <pre><code>root-&gt;next-&gt;price; //that's first_train's price </code></pre>
    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