title: Why doesn't C List Pop work on first run?
body: <p>Just having some trouble implementing a Pop function for my linked-list in C.</p>
  
  <p>It's quite a weird error in that it does NOT work on the first run.</p>
  
  <pre><code>Node * operations = GetOperations(); // Retrieve linked-list of operations
  Print(operations);
  while (1) {
      if (operations == NULL) {
          return 0;
      }
  
      Node * temp = Pop(&amp;operations);
      printf("Node popped is: %s\n", temp-&gt;data);
      Print(operations);
      Node * temp2 = Pop(&amp;operations);
      printf("Node2 popped is: %s\n", temp2-&gt;data);
      Print(operations);
      // Other code down here... //
      return 1;
  }
  </code></pre>
  
  <p>And my code for Pop:</p>
  
  <pre><code>Node * Pop (Node ** head) {
      if (*head == NULL) {
          printf("Error popping! List is empty.\n");
          return NULL;
      }
  
      Node * temp = *head;
      *head = (*head)-&gt;next;
      return temp;
  }
  </code></pre>
  
  <p>Code for my Node:</p>
  
  <pre><code>typedef struct node {
      char * data;
      struct node * next;
  } Node;
  </code></pre>
  
  <p>And when I run the program with GetOperations returning (where <code>-&gt;</code> represents the next node):</p>
  
  <pre><code>Op1-&gt;Op2-&gt;Op3...
  </code></pre>
  
  <p>I get the following output:</p>
  
  <pre><code>Operations: Op1-&gt;Op2-&gt;Op3
  Node popped is: (null)
  Operations: Op1-&gt;Op2-&gt;Op3
  Node2 popped is: Op1
  Operations: Op2-&gt;Op3
  </code></pre>
  
  <p>So as you can see, the first <code>pop</code> never works.</p>