title: Infinite loop in insertion in linked list
body: <p>While inserting node at end in linked list ,my code is running in infinite loop.
  <br><strong>IDE Used-Eclipse</strong>
  <strong>64 bit OS</strong></p>
  
  <pre><code> #include&lt;stdio.h&gt;
   #include&lt;stdlib.h&gt;
   typedef struct Node
     {
       int info;
       struct Node *next;
  
     }node;
     node *head;
     node *ptr1;
     void insert(int x);
     void show();
     int main()
     {
       int i,x,n;
       puts("Enter number of elements\n");
       scanf("%d",&amp;n);
       for(i=0;i&lt;n;i++)
         {
         puts("Enter elements");
         scanf("%d",&amp;x);
         insert(x);
  
         }
      show();
      return 0;
       }
  </code></pre>
  
  <p>//To insert the data in linked list</p>
  
  <pre><code>    void insert(int x)
      {
        node *ptr;
        ptr1=head;
        ptr=(node*)malloc(sizeof(node));
        ptr-&gt;info=x;
        if(head==NULL)
          {
           ptr-&gt;next=head;
           head=ptr;
          }
        else
          {
          ptr1-&gt;next=NULL;
          ptr1=ptr;
          }
         }
  </code></pre>
  
  <p>//To print the details of list
        //Unable to figure out this function</p>
  
  <pre><code>    void show()
      {
      while(ptr1-&gt;next!=NULL)
        {
        printf("%d\n",ptr1-&gt;info);
        ptr1=ptr1-&gt;next;
        }
  
  
  
  }
  </code></pre>