Inserting text in a file @ certain point?


I have this code:-



FILE * fp;
fp = fopen ( "file.txt" , "w" );
fputs( "Here is a load of writing that I have just writen
", fp );
fseek ( fp , 11 , SEEK_SET );
fclose ( fp );


The code moves along till the 11th character in the file, and inserts the character '#'

When I run this code I get this:-

[J@localhost ~]$ cat file.txt
Here is a l#ad of writing that I have just writen
[J@localhost ~]$

However, instead of over writing the 'o' in "load" I want it to insert it, like this:-

"Here is a l#oad of writing that I have just writen"

Is there a way of doing this besides storing everything past the 11th character in memory, inserting the # then writing the rest of the content back to the file?


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!