0

Is there any simple way to insert an external text to some place within a text file ?

I mean , suppose I have a file which has the following line

Hello world !

and I want to add, say, "_, _" between 'Hello' and 'world'.

What I used to do is to use fseek(file,n,SEEK_CUR) , in order to go to some place in the file , and use fprintf to print into the file in that place .However, as expected, the text is Hello_, _ld !

Do I have to store the last half of the text in some variable , then add my external text , then add that half again ?

or is there a simple way of inserting the text without editing the original content ?

  • 3
    [How do I insert and delete some characters in the middle of a file?](http://stackoverflow.com/q/2431073/669576) – 001 Jun 03 '16 at 14:09

1 Answers1

0

Just copy the data to a new file, inserting the text half way. Delete the old file and rename the new.

Ant
  • 1,668
  • 2
  • 18
  • 35