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

Question on CFile::Seek 1

Status
Not open for further replies.

LizardKingSchwing

Programmer
Oct 12, 2001
96
NL
This should be easy but I'm getting spurious results while trying / testing it out ....

Basically I open a CStdioFile and use ReadString until end of file. Upon reading in a certain keyword say Key1, I then read the next 3 lines in and check for other different keywords, say Key2,Key3,Key4.

However if a Key1 value is in any of these lines it will be missed upon the next read cos the file pointer has now passed it by.

To fix this I put in a check for Key1 in the second stage and if found I used CFile::Seek to move the pointer back

What I need to know is how to determine how to move the file back 1 or 2 lines

anyone with any info. help , guides etc. please

Cheers

LK--<
 
If your lines are not a set length then you will have to record their position before reading them in;
DWORD StorePosition = CStdioFile::GetPosition()

If you then require to move to that position simply use seek;
CStdioFile::Seek(StorePosition,CFile::begin)
 
Yeah I'm doing that however ; whats happening is for the most part the file pointer is going back to a few bytes ahead of the position read in, and in one case it goes to about 12 bytes in and this messes things up cos the keywords are missed....

is there an issue with ReadString or does the GetPosition value return incorrect info. The Seek seems to be working as it returns the same Position as I enter in the position section eg.
if the line read in was
&quot;blah key1 blah blah&quot; //get Position = 346
myFile.Seek(346,Cfile::begin) //returns 346

but next ReadString would give partial line
&quot;blah blah&quot; // and key1 would not be parsed

Any ideas...

cheers

LK--<
however the next readString would
 
How are you opening the file, are you specifying CFile::typeBinary ?
 
myFile.Open(csFileName, CFile::modeRead|CFile::shareDenyWrite , &fileException )

should I open it as binary too....
 
Don't answer that

I changed to typBinary and seek positioning works fine

HalleluJah

Thank u very much

Cheers

LK--<
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top