title: File Writing using fopen_s() & fseek() with SEEK_END
body: <p><strong>Situation</strong></p>
  
  <p>I'm trying to programatically write some code to a file to then be compiled. I need to be able to add code in without replacing the whole file. I have a <code>}</code> on the end of the file, which I need to remove to be able to add the next lot of code, after which the <code>}</code> is readded.</p>
  
  <p>My code is currently thus:</p>
  
  <pre><code>    //Writes from an offset from the end of a file.
      static bool Write(const char *FilePath, const char *Text)
      {
          FILE *f;
          errno_t error;
          int seekerror;
          if (!(error = fopen_s(&amp;f, FilePath, "w")))
          {
              //one byte offset from the end of the file.
              if (!(seekerror = fseek(f, -1, SEEK_END)))
              {
                  fwrite(Text, sizeof(char), strlen(Text), f);
                  fclose(f);
                  return true;
              }
          }
          return false;
      }
  </code></pre>
  
  <p><strong>Issue</strong></p>
  
  <p>I believe the <code>w</code> and <code>a</code> flags override the pointer location from <code>fseek()</code>? So I don't seem to be able to overwrite the <code>}</code> at the end of the file.</p>
  
  <p><strong>Does anyone know how I'd be able to write from an offset using <code>SEEK_END</code>?</strong></p>