title: How to write on a specific line in a file?
body: <p>I want to write some data on an already existing file. It is a file that contains about 8-10 lines of header(# comments) and then thousands of lines of <code>data values</code>. What i want is to keep the header same but add the updated <code>data values</code> to the file. It is quite possible that after the update I have less number of lines of <code>data values</code>.</p>
  
  <p>So basically i want to erase everything after the  last # comment in the header and then start writing the new values from there onwards. Is that possible?</p>
  
  <p>Here is an example:</p>
  
  <blockquote>
    <p><em><strong>Original File</em></strong></p>
  </blockquote>
  
  <pre><code>#Program
  #Date
  #Hello
  0 23 23 54
  1 12 4 2
  2 253 786 9887
  3 3 23 54
  4 1 4 4
  5 23 6 81
  </code></pre>
  
  <blockquote>
    <p><em><strong>Updated File</em></strong></p>
  </blockquote>
  
  <pre><code>#Program
  #Date
  #Hello
  0 2 23 54
  2 253 786 9887
  5 23 6 81
  </code></pre>
  
  <p>The code i am editing is using <code>fopen</code> to read the file and <code>fprintf</code> to write to it. I would prefer if the answers are along these lines so that i don't have to change those two.</p>