title: Add a line of text after the nth line in a txt file using c file handling
body: <p>I want to add a line of text after the fifth line in a text file.This is my code:</p>
  <pre><code>#include &lt;stdio.h&gt; 
  
  int main(){
    FILE *f;
    f = fopen(&quot;file1.txt&quot;, &quot;r&quot;);
  
    int nCount = 0;
    char c = fgetc(f);
    while(nCount != 5){
      if(c == '\n'){
        nCount++;
      }
      // c = fgetc(f);
      fseek(f, 1, SEEK_SET);
    }
  
    c = fgetc(f);
  
    fprintf(f, &quot;I have appended a line&quot;);
    
   
    return 0;
  }
  </code></pre>
  <p>Line is not being appended.What is wrong?</p>