Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Writing data at end of file

Status
Not open for further replies.

dominochmiel

Programmer
Jan 28, 2003
40
PL
I have big text file.I need to write small number of bytes at end of this file. Can I do it without reading whole file??
Thanks for help.
 
Easily, just open the file and read the file lenght and do a FILESEEK to the end. Depending on the way you use to open there can be an append-mode (open existing file and append to end of file...), just use suitable mode.

Totte
 

FILE *file;

if ((file = fopen("Logfile.txt", "a")) != NULL)
{
fprintf (file, "%s", string);
}

tomcruz.net
 
Both valid ways. Here's an example of the first way mentioned:

int FilePtr = FileOpen("Filename.txt", fmOpenWrite);
int Buffer = 2;

if (FilePtr)
{
FileSeek(FilePtr, 0, 2);
FileWrite(FilePtr, &Buffer, sizeof(Buffer));
FileClose(FilePtr);
}

If you need to write to the file really fast, I suggest using the c routines in the second example given.

Chris
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top