Sender: nate AT cartsys DOT com Message-ID: <3564FFB4.A9F56566@cartsys.com> Date: Thu, 21 May 1998 21:31:48 -0700 From: Nate Eldredge MIME-Version: 1.0 To: JCx CC: djgpp AT delorie DOT com Subject: Re: Problem writing in a file... References: <6jv6lo$73e$1 AT news3 DOT isdnet DOT net> Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Precedence: bulk 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