Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > C++ > File IO Questio...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 4 Topic 43235 of 48020
Post > Topic >>

File IO Question

by JackC <jecheney@[EMAIL PROTECTED] > Feb 11, 2008 at 11:17 AM

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
 




 4 Posts in Topic:
File IO Question
JackC <jecheney@[EMAIL  2008-02-11 11:17:43 
Re: File IO Question
Rolf Magnus <ramagnus@  2008-02-11 20:25:05 
Re: File IO Question
JackC <jecheney@[EMAIL  2008-02-11 11:39:13 
Re: File IO Question
"Jim Langston"   2008-02-12 00:09:26 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Tue Oct 14 8:56:44 CDT 2008.