Hi, I'm trying to add some strings inside a file in specific locations.
I'm opening a file with fopen and "r+a"
and after a while i'm trying to add strings that way:
But "My new string" will overwrite the next chars from the file.
example:
origin file:
a
b
c
I want to append here
d
e
fffffffffffffff fffffffffffff
overwrited file
a
b
c
I want to append here
My new string
fffffffffffffff fff
How can I deal with this problem?
Thanks in advanced,
Gil
I'm opening a file with fopen and "r+a"
and after a while i'm trying to add strings that way:
Code:
char *line = (char *) malloc(MAX_LINE); while (fgets(line, sizeof(line), theFile) != NULL) if (strstr(line, "I want to append here") != NULL) fputs("My new string", theFile);
example:
origin file:
a
b
c
I want to append here
d
e
fffffffffffffff fffffffffffff
overwrited file
a
b
c
I want to append here
My new string
fffffffffffffff fff
How can I deal with this problem?
Thanks in advanced,
Gil
Comment