Original Post
Hi every-1.
Could someone shed light on this please? I intend to make a program that adds lines to a file, at the beginning, for the moment. The problem is I don't know whether I really must copy the whole file's content in order to copy it back behind the line added.
It would be something like :
void AddLine(char *str, char *filename){
int n;
char *buffer = null;
fstream fstr(filename,ios::in|ios::out);
fstr.seekg(0,ios::end);
n = fstr.tellg();
n += strlen(str);
n += 1; // for the null character
buffer = new char[n];
strcpy(buffer,str);
fstr.seekg(0, ios::beg);
fstr.read(buffer+strlen(str));
buffer[n] = 0;
/*for those who don't like reading, it's just something that copies the
whole file in abuffer after having copied into this same buffer the string
to add at the beginning. Then rewrite everything to the same file and
save it.
Some instructions are missing here but don't report me them, they're already corrected in the final version. ;-)
This will then make a pretty cool Linux command : add MyAss
AnyFile.txt*/
Prog, Hex & Rock'n'Roll :
I don't like the Prog but the Prog likes me.
Some nice poetry to sweeten your spirit and relax a bit before programming
[edited by - kurtcpp on January 28, 2004 8:09:07 AM]
[edited by - kurtcpp on January 28, 2004 8:11:34 AM]