title: Writing to File with Offset
body: <p>I'm trying to write a simple block of code that writes the contents of an array to a position in a file. The file is a simple, text only file. It seems to do everything write, but file contents end up in hex (with a bunch of zeroes at the beginning). I'm using the following:  </p>
  
  <pre><code>FILE * fp; // file to write to
  void fwritel(long offset, char * data) {
      fp = fopen(filename, "w");  
      fseek(fp, offset, SEEK_SET);
      fwrite(data, 1, strlen(data) - 1, fp);
      fclose(fp);
  }
  </code></pre>
  
  <p>I've also used a variation of <code>pwrite</code> that didn't work: <code>pwrite(fp, data, strlen(data) - 1, offset);</code> The code I'm looking for would write <code>data</code> at position <code>offset</code> only modifying the file from <code>offset</code> to <code>offset + strlen(data)</code>.</p>