title: Linked list program in C hangs
body: <p>I am writing a linked list program 
  to add items and display those items.
  I am able to add first item successfully,
  but error occurs while adding the second item.
  I tried to figure out the error,but
  everything looks fine to me.
  The program hangs,here is my code:</p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;stdlib.h&gt;
  
  struct link_list
   {
    int number;
    struct link_list *next;
   };
  
   typedef struct link_list node;
   node *head;
  
   void add(int num)
   {
     node *newnode,*current;
     newnode = (node *)malloc(sizeof(node));
     newnode-&gt;number = num;
     newnode-&gt;next = NULL;
    if(head == NULL)
     {
       head = newnode;
       current = newnode;
     }
   else
     {
       current-&gt;next = newnode;
       current = newnode;
     }
  }
  
  void display(node *list)
  {
   list = head;
   if(list == NULL)
    {
       return;
    }
   while(list != NULL)
   {
       printf("%d",list-&gt;number);
       list = list -&gt; next;
   }
   printf("\n");
  }
  
  int  main()
   {
   int i,num;
   node *n;
   head=NULL;
   while(1)
    {
      printf("\nList Operations\n");
      printf("===============\n");
      printf("1.Insert\n");
      printf("2.Display\n");
  
      printf("3.Exit\n");
      printf("Enter your choice : ");
      if(scanf("%d",&amp;i)&lt;=0)
      {
          printf("Enter only an Integer\n");
          exit(0);
      }
      else
      {
          switch(i)
          {
              case 1:
                       printf("Enter the number to insert : ");
                       scanf("%d",&amp;num);
                       add(num);
                       break;
              case 2:
                     if(head==NULL)
                      {
                      printf("List is Empty\n");
                      }
                      else
                      {
                      printf("Element(s) in the list are : ");
                      }
                      display(n);
                      break;
              case 3:     return 0;
              default:    printf("Invalid option\n");
          }
      }
    }
    return 0;
  }
  </code></pre>