title: Trouble with insertion of C string into linked list
body: <p>I am writing a program to read a file and then store the data into a linked List.</p>
  
  <p><strong>linkedList.h</strong></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  #include&lt;stdbool.h&gt;
  
  struct linked_list
  {
      char *stock_name;
      double stock_price;
      struct linked_list *next;
  };
  
  typedef struct linked_list NODE;
  
  NODE* insert(NODE *head, double stock_price, char *stock_name);
  void printList(NODE *head);
  </code></pre>
  
  <p><strong>linkedList.c</strong></p>
  
  <pre><code>#include&lt;stdio.h&gt;
  #include&lt;stdlib.h&gt;
  #include&lt;string.h&gt;
  #include&lt;stdbool.h&gt;
  #include"linkedList.h"
  
  void printList(NODE *head)
  {
      NODE *this = head;
  
      while(this != NULL)
      {
          printf("stock name:%s , stock price:%lf\n", this-&gt;stock_name, this-&gt;stock_price);
          this = this-&gt;next;
      }
  
  }
  
  
  NODE* insert(NODE *head, double stock_price, char *stock_name)
  {
      NODE *newNode = malloc(sizeof(NODE));
  
      if(head == NULL)
      {
          newNode-&gt;stock_price = stock_price;
          newNode-&gt;stock_name = stock_name;
          head = newNode;
      }
      else
      {
          newNode-&gt;stock_price = stock_price;
          newNode-&gt;stock_name = stock_name;
  
          newNode-&gt;next = head;
          head = newNode;
      }
      return head;
  }
  </code></pre>
  
  <p><strong>main.c</strong></p>
  
  <pre><code>#include &lt;stdio.h&gt;
  #include &lt;stdbool.h&gt;
  #include &lt;string.h&gt;
  #include "linkedList.h"
  
  NODE *head;
  bool headNode = true;
  
  void insertIntoLinkedList(char *stock_name, double stock_price);
  
  int main ( int argc, char *argv[] )
  {
      head = malloc(sizeof(NODE));
  
      double stock_price;
      char stock_name[100];
      int stock_name_counter = 0;
  
      **..then I read the file..**
  
  
      stock_name[stock_name_counter] = '\0'; //to end my C string
      stock_name_counter = 0;  //this is used for reading char
  
      insertIntoLinkedList(stock_name, stock_price); //I double checked here,the name and price is correct
           **......**
      printList(head); //**Not the output I want**
      fclose( file );
  
  
  void insertIntoLinkedList(char *m_stock_name, double m_stock_price)
  {
      if(headNode == true)
      {
          head = insert(NULL, m_stock_price, m_stock_name);
          headNode = false; //this is used to insert data to my linked list for the first time
      }
      else
      {
          head = insert(head, m_stock_price, m_stock_name);
      }
  }
  </code></pre>
  
  <p>Here is the problem:  if the file contains:
  YAHOO 120
  GOOGLE 10
  APPLE 199</p>
  
  <p>my printList() gave me this:
  APPLE 120
  APPLE 10
  APPLE 199</p>
  
  <p>I have been trying to debug for hours and still cannot figure why the name is not stored in my linked list properly(but the price is store properly..)...any help will be appreciate :)</p>