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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

reverse reading

Status
Not open for further replies.

ravenspawn

Technical User
May 3, 2001
13
US
how would I read a random-access file backwards?
 
what do you mean random access backward? can you give a short sample? John Fill
1c.bmp


ivfmd@mail.md
 
Get the length of the file, set the file pointer to the end of the file (length) - the size of the buffer, then move the file pointer backwards from there in a loop...

i.e.

1) file pointer position = length of file - sizeof(buffer)

2) read data into buffer

3) set file pointer position = file pointer position - sizeof(buffer)

4) loop steps 2 and 3 until file position is 0/BOF Rob Marriott
rob@career-connections.net
 
fseek(yourFilePtr,offset,seektype) where seektype can be:
SEEK_CUR - current position
SEEK_END - end of file
SEEK_SET - begin of file
for reading file you can use fscanf.
There also exists many easyest function in STL, MFC.
John Fill
1c.bmp


ivfmd@mail.md
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top