title: Getting input into a linked list using a loop
body: <p>I made this program to learn about linked lists as I am just starting out with them. The program terminates immediately after the statement "Enter the amount of pesticide"(it is a school assignment). Also, I am unsure how do I keep the length of the list limited to the size input by the user.</p>
  
  <pre><code>#include&lt;stdio.h&gt;
  
  struct plants{
      int val;
      struct plants *next;
  };
  
  void printlist();
  
  int main(){
      struct plants* head = NULL;
      struct plants* current= head;
      head = malloc(sizeof(struct plants));
      int counter,size;
  
      printf("Enter the number of plants\n");
  
      scanf("%d",&amp;size);
  
      printf("Enter the amount of pesticide each plant has.\n");
  
      while(current!=NULL){
          scanf("%d",current-&gt;val);
          current= current-&gt;next;
      }
      return 0;
  }
  </code></pre>