title: How to properly append lines to already existing file
body: <p>I looked over the internet trying to find a solution for writing line by line into a file in c. I found solutions like changing the mode of <code>fopen()</code> to <code>w+</code>, <code>wt</code>, <code>wb</code> but it did not work for me. I even read to put <code>\r</code> instead of <code>\n</code> in the end of the line but still when I try to write to the file the only thing that is written there is the last line.</p>
  
  <pre><code>    FILE *log = NULL;
      log = fopen(fileName, "w");
      if (log == NULL)
      {
          printf("Error! can't open log file.");
          return -1;
      }
  
      fprintf(log, "you bought %s\n", pro[item].name);
      fclose(log);
  </code></pre>
  
  <p>Many thanks for your time and help.</p>