title: simple linked list implementation logical error?
body: <p>I have implemented a linked list code, but it seems that there is somewhere a logic error in my code, can anyone help me to fix this problem?</p>
  
  <pre><code>struct Node{
    int val;
    struct Node *next;
  };
  void add(struct Node *new_node, struct Node *head){
   struct Node *new_n;
   if( head == NULL){
    head = new_node;
   }
   else{
    new_n = head;
    while(new_n){
      new_n =  new_n-&gt;next;
    }
    new_n = new_node;
   }
  }
  void print(struct Node*n){
    while(n != NULL){
     fprintf(stderr, "val:%d addr%p \t next%p\n",n-&gt;val, n, n-&gt;next);
     n=n-&gt;next;
    } 
  }
  
  void main (){
   struct Node *head;
   struct Node *node;
   int i ;
   for( i =1; i&lt; 5; i++){
     struct Node *node = malloc(sizeof(*node));
     bzero(node,sizeof(*node));
     node-&gt;val = i;
     node-&gt;next =NULL;
     add(node, head);  
   }
   print(head);
  }
  </code></pre>
  
  <p>This code doesn't print any values? What are the problems with this code?
  [ I used: $gcc filename.c -o  filename.o] </p>