modify existing contents of file in c
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; } As one can see that I want to edit abc.txt in such a way that i is replaced by a in it. The program works fine but when I open abc.txt externally, it seemed to be unedited. Any possible reason for that? Why in this case the character after i is not replace by a , as the answers suggest? Analysis There are multiple problems: fgetc() returns an int , not a