title: Singly Linked List in C incorrect output
body: <p>So I'm doing some linked list revison and Im trying to just load a list with some numbers and then print it out. Below is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  typedef struct stack {
     int data;
     struct stack *next;
  }*stack;
  
  stack create_s(void){
     stack s = (void*)malloc(sizeof(stack));
     s-&gt;next = NULL;
  
     return s;
  }
  
  void push_s(stack s, int data) {
     while (s-&gt;next != NULL) {
        s = s-&gt;next;
        }
  
     s-&gt;next = (void*)malloc(sizeof(stack));
     s=s-&gt;next;
     s-&gt;data = data;
     s-&gt;next = NULL;
  }
  
  void print_s(stack s) {
     if (s==NULL) {
        return;
     } 
     else {
        while (s-&gt;next != NULL) {
           printf("%d\n",s-&gt;data);
           s=s-&gt;next;
        }
     }
  }
  
  int main (void) {
     stack s = create_s();
  
     push_s(s,2);
     push_s(s,4);
     push_s(s,6);
     push_s(s,8);
  
     print_s(s);
  
     return 0;
  }
  </code></pre>
  
  <p>My output is however:</p>
  
  <pre><code>-1853045587
  2
  4
  6
  </code></pre>
  
  <p>when it should be</p>
  
  <pre><code>2
  4
  6
  8
  </code></pre>
  
  <p>Is it printing the address of my struct at the beginning? Also, why is it not printing my last element?</p>
  
  <p>Thanks</p>