Mail Archives: djgpp/1998/05/22/00:37:27
JCx wrote:
>
> Hi there !
>
> I just spent two hours trying to code -without success- the following thing:
> I open a text file, then look for a specific string in this file (with
> fgets) and then, when I find this string, my program is supposed to add
> another string just after the one it found (with fprintf). The problem is:
> the program duplicates everything that stands after the line found, and then
> adds the line I looked for+the line I wanted to add at the end of the file !
>
> To say it clearly:
>
> It opens system.ini : working
> It looks for [drivers32] : working
> I *should* write a string just after this line : bug
>
> Could anyone help me ?
> Source included.
>
> Thanks, JCx.
> jicehix AT worldnet DOT fr
>
> Name: addv.c
> addv.c Type: unspecified type (application/octet-stream)
> Encoding: x-uuencode
First of all, know that what you are trying to do will *overwrite*
whatever follows "[drivers32]". What you probably need to do is read the
file and write to a temp file with the line *added*, then copy it back
over the original.
Also, I believe that a file opened in "+" mode needs to be `fflush'ed
before writing after reading, and vice versa.
--
Nate Eldredge
nate AT cartsys DOT com
- Raw text -