title: C Implementation of linkedlist
body: <p>I am trying to print the values stored in a linked list but i'm running into a infinite loop.Please could some one tell me what is wrong with my code. I am able to successfully collect the data of the nodes but when printing the list i run into a continuous loop. Any help would be greatly appreciated. Thanks in advance</p>
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  
  struct node {
      int data; //4 bytes
      struct node *next; // 4bytes 32 bit and 8 bytes i 64bit cp
  };
  
  int main(){
      struct node *head,*newnode,*temp;
      head = NULL ;
      temp = head;
      int count=0, choice=1;
  
      while(choice){
          newnode = (struct node *)malloc(sizeof(struct node));
          printf(&quot;Enter data:&quot;);
          scanf(&quot;%d&quot;,&amp;newnode-&gt; data);
          newnode-&gt;next = head;
  
          if(head == 0){
              head = temp = newnode;
          }
          else{
              temp-&gt;next = newnode;
              temp = newnode;
  
          }
          printf(&quot; %d &quot;,temp-&gt;data);
  
          printf(&quot;Do you want to continue? 0/1&quot;);
          scanf(&quot;%d&quot;,&amp;choice);
      }
      int i = 0;
      temp = head;
      while( temp!=NULL){
          printf(&quot;%d &quot;,temp-&gt;data);
          temp=temp-&gt;next;
      }
  }
  </code></pre>