title: How to keep track of all nodes in a linkedlist using only one variable?
body: <p>The program will read values that are typed in by the user iteratively in a while loop. Every time the value is read, a new node will be created with this integer value. Now I'll make a LinkedList using these created nodes. And then print out every value stored in the LinkedList. I expect the order of reading in and the order of printing out are reversed. The following is my main function where readline is just a function that prints a message and reads an input, make_new_node is a function that takes in a value and makes a new node with this value, printlink is the function that prints out all the values saved in every node in the linked list, and freelink contains the free function. For now, I only get a printed-out result of the last integer typed in. With just one node variable n, how can I possibly print out all the value members of every node in the linked list?</p>
  
  <pre><code>int main()
  {
      char buf[100];
      int num;
      Node* n = NULL;
  
      while(1) {
          readline("The num to put in?: ", buf, sizeof(buf));
          sscanf(buf, "%d", &amp;num);
          if(num == -1) {
              n -&gt; next = NULL;
              printlink(n);
              freelink(n);    
              break;      
          } else {
              n = make_new_node(num);
              n -&gt; next = n;      
          }               
      }
  
      return 0;
  }
  </code></pre>