Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations cowski on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert line anywhere in .txt file without erasing

Status
Not open for further replies.

rguerrie

New member
Joined
Jul 22, 2003
Messages
1
Location
BE
This may seem a stupid question but I didn't find an ansewer to it...

I'd like to insert lines of data in a .txt file that already contains data.
I tried with fprintf() , helped by fseek() to place the cursor at the beginning of the file for example, but the problem is that when fprintf() writes data in the file, it replaces the data of the file by the data to be written.
(the file has previously been opened wtih fopen(fid,'r+'))

What I'd like to do is inserting my new data, just like I would do if I write my new data at the beginning of the file, remaining the previous data in the following lines.

I also checked if I made an error of the permission of fopen, but it seems that there's no other way to open than r, r+, a, a+, w, ... but no one does what I want ... :(

Help please.... I need quick help.... please

Rolando
 
As a general rule, you can't do that directly in a text file. If you copy the front data into another, append your new data and then the back data, it would work.

TTFN
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top