Computer Science, asked by banti030788, 2 months ago

d) Write the steps to change c
contents completely.​

Answers

Answered by sarveshcpr
0

Explanation:

Questions Jobs Tags Users Badges Ask

Up vote

7

Down vote

modify existing contents of file in c

c edit file-handling

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?

Similar questions