Howdy, Stranger!

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

Categories

Inserting text in a file @ certain point?

Joe2003Joe2003 Member Posts: 92
Hi

I have this code:-

[code]#include

main()
{

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 );
putc('#',fp);
fclose ( fp );

}[/code]

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

When I run this code I get this:-

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

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?

thanks

Joe
Sign In or Register to comment.