title: When opening a file in append mode, how can I reposition the file pointer?
body: <p>I am trying to insert some data into the middle of a file. I have opened the file in append mode as:</p>
  
  <pre><code>file = fopen(msg-&gt;header.filename, "ab");
  </code></pre>
  
  <p>I then tried a seek to the desired offset in the file as so:</p>
  
  <pre><code>fseek(file, msg-&gt;header.offset, SEEK_SET);
  </code></pre>
  
  <p>However, when I then try an fwrite as so:</p>
  
  <pre><code>int bytesWritten = fwrite(msg-&gt;message, 1, msg-&gt;header.length, file);
  </code></pre>
  
  <p>All the data is written to the end of the file instead of in the middle of the file.</p>
  
  <p>Is this because I am using append mode? I would open in write mode, but I need to keep the existing contents in the file.</p>