title: Does fseek() move the file pointer to the beginning of the file if it was opened in "a+b" mode?
body: <p>I wish to open a file using the "a+b" mode, i.e. if it does not exist it is created automatically, but if it does I don't want to overwrite it. I want to be able to read and write to the file.</p>
  
  <p>The file is binary, and I want to save records of a specific <code>struct</code> in it. So I want to do <code>fseek()</code> to the record I want and then save the record using <code>fwrite()</code>.</p>
  
  <p>The code looks as follows (<code>MyRecord</code> is a <code>typedef</code> to a <code>struct</code>, while <code>FILENAME</code> is a <code>#define</code> to the file's name):</p>
  
  <pre><code>int saveRecord(MyRecord *pRecord, int pos)
  {
      FILE* file = fopen(FILENAME, "a+b");
      if (file == NULL)
      {
          printf("Unable to open file %s\n", FILENAME);
          return 0;
      }
  
      fseek(file, pos * sizeof(MyRecord), SEEK_SET);
      fwrite(pRecord, sizeof(MyRecord), 1, file);
      fclose(file);
      return 1;
  }
  </code></pre>
  
  <p>However this code just appends the record to the end of the file, even if I set <code>pos</code> to 0. Why isn't <code>fseek()</code> with <code>SEEK_SET</code> working in append mode?   </p>
  
  <p>I know I can simply open it with "r+b" and if it fails open it with "wb", but I want to know why this doesn't work and why <code>fseek()</code> with <code>SEEK_SET</code> is leaving the file pointer at the end. Any references to places where this behaviour is documented appreciated (because I couldn't find any, or I am using the wrong keywords).</p>