J
JackC
Hi,
Im having some problems working out how I can read the last 5 bytes of
a file which i already have open. Heres what i have tried:
pFile = fopen ("/home/jc/data.txt" , "rw");
// Some IO here (preserve position pointer required)
// Read in last 5 bytes
fseek(pFile, 5, SEEK_SET);
fgets(buffer, 5, pFile);
// More IO here (resume old position pointer)
fclose(pFile);
This doesn't work because SEEK_SET adds 5 onto the end of the file, i
need a way to set the position to the current end - 5 bytes, whilst
preserving the current position once im done.
Any ideas on how to approach this? I thought about getting the file
size and using fseek with SEEK_SET from the beginning of the file, but
i think this would involve closing/reopening the file which i would
like to avoid.
Thanks alot for any help,
Jack
Im having some problems working out how I can read the last 5 bytes of
a file which i already have open. Heres what i have tried:
pFile = fopen ("/home/jc/data.txt" , "rw");
// Some IO here (preserve position pointer required)
// Read in last 5 bytes
fseek(pFile, 5, SEEK_SET);
fgets(buffer, 5, pFile);
// More IO here (resume old position pointer)
fclose(pFile);
This doesn't work because SEEK_SET adds 5 onto the end of the file, i
need a way to set the position to the current end - 5 bytes, whilst
preserving the current position once im done.
Any ideas on how to approach this? I thought about getting the file
size and using fseek with SEEK_SET from the beginning of the file, but
i think this would involve closing/reopening the file which i would
like to avoid.
Thanks alot for any help,
Jack