title: modify existing contents of file in c
body: <pre><code>int main()
  {
      FILE *ft;
      char ch;
      ft=fopen("abc.txt","r+");
      if(ft==NULL)
      {
          printf("can not open target file\n");
          exit(1);
      }
      while(1)
      {
          ch=fgetc(ft);
          if(ch==EOF)
          {
              printf("done");
              break;
          }
          if(ch=='i')
          {
              fputc('a',ft);
          }
      }
      fclose(ft);
      return 0;
  }
  </code></pre>
  
  <p>As one can see that I want to edit <code>abc.txt</code> in such a way that <code>i</code> is replaced by <code>a</code> in it.<br>
  The program works fine but when I open <code>abc.txt</code> externally, it seemed to be unedited.<br>
  Any possible reason for that?</p>
  
  <p>Why in this case the character after <code>i</code> is not replace by <code>a</code>, as the answers suggest?</p>