title: insert linked list nodes in a loop
body: <p>I'm using strtok() to parse an input, convert the string into an int and then insert this int value into a linked list all in a while loop.</p>
  
  <p>This is what I'm trying to do (I haven't written the code explicitly but I'm planning to do do something as follows):</p>
  
  <pre><code>while(fgets(&amp;string,LMAX,fp) != NULL){
  
  //get first token using strtok
  //convert to int
  //insert into linked list
  
  while (token != NULL){
  
  //get next token in the line
  //do the same as above
  }
  }
  </code></pre>
  
  <p>I already have written a function that is supposed to insert a node into the linked list and it is as follows:</p>
  
  <pre><code>void insert_node(struct Cons *head_pointer, int data){
  struct Cons *new = (struct Cons*) malloc(sizeof(struct Cons));
  struct Cons *current = head_pointer;
  new-&gt;head = data;
  new-&gt;tail = NULL;
  
  if (head_pointer-&gt;tail == NULL){
  head_pointer-&gt;tail = new;
  }
  else
  {
  
  while (current-&gt;tail != NULL){
  current = current-&gt;tail;
  }
  current-&gt;tail = new;
  }
  free(current);
  current = NULL;
  }
  </code></pre>
  
  <p>The struct definition is also as follows:</p>
  
  <pre><code>typedef int element_t;
  
  typedef
  struct Cons {
    element_t head;
    struct Cons* tail;
  } Cons;
  </code></pre>
  
  <p>Can anyone suggest how I can go about doing this? </p>