title: trying to append new text to an existing file using fwrite() with mode "a+" but get weird string written
body: <p>I am writing a program that is to insert texts to a file every time when it is called. I don't want to rewrite the entire file, and I want the new text could be inserted to a new line. Here is my test code:</p>
  
  <pre><code>void writeFile()
  {
      FILE *pFile;
      char* data = "hahaha";
      int data_size = 7;
      int count = 1;
      pFile = fopen("textfile.bin","a+");
      if (pFile!=NULL)
      {
          fwrite (data, data_size, count, pFile);
          fclose (pFile);
      }
  }
  </code></pre>
  
  <p>At the first time it got called, everything worked fine. A new file was created and the data was successfully written. But when I called it again and expected that a new data to be inserted, I got weird strings in the file, something like:慨慨慨栀桡桡a.</p>
  
  <p>I am not really familiar with C++ I/O functions. Can someone tell me what I did wrong? Also, any suggestion for appending text to the next line?</p>