title: Writing linked list to txt file(Saving process)
body: <pre><code>struct node
  {
  string info;
  struct node *next;
  }*start, *last;
  
  long nodecount=0;
  class teditor
  {
  public:
      node* create_node(string);
      void insert_pos();
      void save();
      void display();
      void delete_pos();
      teditor() 
      {
          start = NULL;
      }
   };
   node *teditor::create_node(string value)
  {
  struct node *temp, *s;
  temp = new(struct node); 
  if (temp == NULL)
  {
      cout&lt;&lt;"Memory not allocated "&lt;&lt;endl;
      return 0;
  }
  else
  {
      temp-&gt;info = value;
      temp-&gt;next = NULL;     
      return temp;
   }
  }
  void teditor::save()
  {   
  struct node *info;
  ofstream listfile;
  listfile.open("example.txt",ios::out|ios::app |ios::binary) ;
  node *temp;
  temp=start;
  if(!listfile){
   cout&lt;&lt;"\nError";
   }
   else{
  while(temp!=NULL)
  {
      listfile.write((char*)(temp),sizeof(nodecount));
      temp=temp-&gt;next;
  }
  }   
  listfile.close();
  cout&lt;&lt;"\n\n\n\t\tLink list has been saved in file example.txt in current folder.";
  cout&lt;&lt;"\n\n\t\tPress a key to continue ... ";getch();
  }
  void teditor::insert_pos()
  {
  string value; int counter;
  int pos;
  cout&lt;&lt;"Enter the value to be inserted: ";
  cin&gt;&gt;value;
  struct node *temp, *s, *ptr;
  temp = create_node(value);
  cout&lt;&lt;"Enter the postion at which node to be inserted: ";
  cin&gt;&gt;pos;
  nodecount++;
  int i;
  s = start;
  while (s != NULL)
  {
      s = s-&gt;next; counter++;
  }
  if (pos == 1)
  {
      if (start == NULL)
      {
          start = temp;
          start-&gt;next = NULL;
      }
      else
      {
          ptr = start;
          start = temp;
          start-&gt;next = ptr;
      }
  }
  else if (pos &gt; 1 )
  {
      s = start;
      for (i = 1; i &lt; pos; i++)
      {
          ptr = s;
          s = s-&gt;next;
      }
      ptr-&gt;next = temp;
      temp-&gt;next = s;
   }
  else
  {
      cout&lt;&lt;"Positon out of range"&lt;&lt;endl;
  }
  }
  
  void teditor::display() 
  {
  /*
  Need to merge as a string and show to display just in one line like writing
  why cannot save health because of application saving pointers.
  */
  node *temp;
  temp=start;
  cout&lt;&lt;"\n\n\n";
  while(temp)
  {
      cout&lt;&lt;"\t\t\t"&lt;&lt;temp-&gt;info;
      temp=temp-&gt;next;
  }
  cout&lt;&lt;"\n\n\t\t "&lt;&lt;nodecount&lt;&lt;" records displayed ,Press a key to continue.....";getch();
  }
  void teditor::delete_pos()
  {
  int pos, i, counter = 0;
  if (start == NULL)
  {
      cout&lt;&lt;"List is empty"&lt;&lt;endl;
      return;
  }
  cout&lt;&lt;"Enter the position of value to be deleted: ";
  cin&gt;&gt;pos;
  struct node *s, *ptr;
  s = start;
  if (pos == 1)
  {
      start = s-&gt;next;
  }
  else
  {
      while (s != NULL)
      {
          s = s-&gt;next;  
      }
      if (pos &gt; 0 &amp;&amp; pos &lt;= counter)
      {
          s = start;
          for (i = 1;i &lt; pos;i++)
          {
              ptr = s;
              s = s-&gt;next;
          }
          ptr-&gt;next = s-&gt;next;
      }
      else
      {
          cout&lt;&lt;"Position out of range"&lt;&lt;endl;
      }
      free(s);
  }cout&lt;&lt;s&lt;&lt;" Element Deleted"&lt;&lt;endl;nodecount--;
   cout&lt;&lt;"There is left "&lt;&lt;nodecount&lt;&lt;" nodes"&lt;&lt;endl; 
  
    }
  </code></pre>
  
  <p>Hi,guys!I have problem while I trying to save my linked list to txt.Everytime I tryin and txt gave me a chinese writing.Teacher also said I need to merged with string or I need to give node to string that application can easily save that string line.Maybe because of I 'm trying to write <code>node *temp</code>.Anybody know how can I solve my problem?After other processes it will be copy,cut,paste and replace with nodes.</p>