View Single Post
inserting stuff into a file
Old
  (#1)
Cheeseh
[rcbot]
 
Cheeseh's Avatar
 
Status: Offline
Posts: 361
Join Date: Dec 2003
Location: China
Default inserting stuff into a file - 29-03-2004

heyo..

here is what I want to do,

I want to change a line in a ascii file, but it means it will probably make the line longer as I'm adding more characters, the problem with this is the when writing to the file it overwrites it doesn't insert, (you'll know the difference between this if you type with the insert key pressed once :p) so it will eventually overwrite stuff I want to keep after the line, because it is overwriting instead of inserting..

can I do this?

this is what i'm doing atm,..
Code:
if ( linechanged )
{
// fpos = current file position (start of line)
// add i to get the character of the start of the change

	fseek(fp,fPos+i,SEEK_SET);
// print the drive name into the file at this point (as it is missing it, 
// this is what I want to insert here)
	fprintf(fp,drive);
	fflush(fp);
// back to the start of the lien, this is inside a loop and 
// will check the line again until no more changes need to be done
	fseek(fp,fPos,SEEK_SET);
}
  
Reply With Quote