Hello guys,
How can I read and write in the same file? I want to open a file that exists and write something in the end of each line of the file..
Ex:
My_file:
a b c
d e f
g h i
I want to alter to:
a b c XX
d e f XX
g h i XX
I tried this but the file does not altered..
#include <stdio.h>
#include <stdlib.h>
int main()
{
FILE *f;
f = fopen("file.txt", "a+");
while (fgets(line,sizeof(line),f)){
fputc("XX",f);
}
fclose(f);
return 0;
}
I tried a lot of thing like open in other modes, and nothing
thanks