title: How to save readline history in a text file and call it afterwards
body: <p>Is it possible to save readline history in a text file and get the history after I reopen my program...</p>
  
  <pre><code>char *line, *expansion;
  int result;
  
  stifle_history(7);
  
  while ((line = readline(" $ ")) != NULL) {  
  
          result = history_expand(line, &amp;expansion);
  
          rl_bind_key('\t',rl_complete);
  
          if (result)
                  fprintf(stderr, "%s\n", expansion);
  
          if (result &lt; 0 || result == 2) {
                  free(expansion);
                  continue;
          }
  
          strncpy(line, expansion, sizeof (line) - 1);
          free(expansion);
          read_history("history_file");
          write_history("history_file");
  
          register HIST_ENTRY **the_list;
          register int i;
  
          if (the_list)
                  for (i = 0; the_list[i]; i++)
                          printf("%d: %s\n", i + history_base, the_list[i]-&gt;line);
  
          if (strlen(line) &gt; 0) 
                  add_history(line);
  </code></pre>
  
  <p>I improved my code a bit. Please show the the correct way how I can fix my code to save history in a text file retrieve it afterwards.</p>