title: How to insert text into a file using fseek and fwrite
body: <p>How to make <code>fseek</code> not overwrite what was at the given position when used with <code>fwrite</code>?</p>
  
  <p>I am opening a file with </p>
  
  <pre><code>file = fopen(filename, "r+");
  </code></pre>
  
  <p>and then use</p>
  
  <pre><code>fseek (file, pos, SEEK_SET);
  </code></pre>
  
  <p>to go to the position I need, using</p>
  
  <pre><code>fwrite(text, 1, text_size, file);
  </code></pre>
  
  <p>to write the data.</p>
  
  <p><strong>example:</strong></p>
  
  <p>Say, I want to add '7' at position 3:</p>
  
  <pre><code>abcdef
  </code></pre>
  
  <p>I want this to be</p>
  
  <pre><code>abc7def
  </code></pre>