title: dummy value came out in C
body: <pre><code>typedef struct _node{
    int count;
    char * command;
    struct _node * next;
  }Node;
  
  typedef struct _list{
    Node * head;
    Node * cur;
    Node * tail;
  }List;
  
  List * history;
  
  void list_init()
  {
    history = (List*)malloc(sizeof(history));
    history-&gt;head = history-&gt;cur = history-&gt;tail = NULL;
  }
  
  char * copy_command(char * command, int len)
  {
     char * temp_command = (char*)malloc(sizeof(char)*(len+1));
     strncpy(temp_command, command, len+1);
     return temp_command;
  }
  
  void insert_history(int cnt, char * command)
  {
    Node * temp = (Node*)malloc(sizeof(Node));
    temp-&gt;count = cnt;
    temp-&gt;command = command;
    temp-&gt;next = NULL;
  
    if(history-&gt;head == NULL){
      printf("hello %s\n", command);
      history-&gt;head = temp;
      printf("hello2 %s\n", temp-&gt;command);
    }
    else
      history-&gt;cur-&gt;next = temp;
  
    printf("head hello %s\n", history-&gt;head-&gt;command);
    history-&gt;cur = temp;
    history-&gt;tail = temp;
  }
  
  
  void print_history()
  {
    history-&gt;cur = history-&gt;head;
    printf("history head: %s   | ", history-&gt;head-&gt;command);
  
    while(history-&gt;cur != NULL){
      printf("%-3d %s\n", history-&gt;cur-&gt;count, history-&gt;cur-&gt;command);
      history-&gt;cur = history-&gt;cur-&gt;next;
    }
  
    history-&gt;cur = history-&gt;tail;
  }
  </code></pre>
  
  <p>Hi, all.
  When I call this one,</p>
  
  <pre><code>char str[30] = "history";
  list_init();
  cur_command = copy_command(str, strlen(str))
  insert_history(1, cur_command);
  print_history();
  </code></pre>
  
  <p>I got </p>
  
  <blockquote>
    <p>hello history <br>
        hello2 history <br>
        head hello history <br>
        history head: �&amp;@��   | 1   �&amp;@��</p>
  </blockquote>
  
  <p>history is a global value which contains pointers to node.<br>
  It's okay when I print history->head->command in the insert_history() function,<br>
  but it's not okay when I print history->head->command in the print_history() function <br>
  It's working as I expected when I call above code twice, <br>
  but it doesn't work when I call it first time.
  I don't know what should i do.</p>