Re: Offset by 1 in CStdiofile Seek while reading 0xa

Tech-Archive recommends: Fix windows errors by optimizing your registry



"Ganga Sridhar" <gangasridhar@xxxxxxxxxxxxxxx> wrote in message
news:uY1ds3MsIHA.484@xxxxxxxxxxxxxxxxxxxx
In my VC++ program I am reading a file in text mode using CStdioFile.
I am trying to read the file character by character until I encounter
the token (Decimal 10 / 0xa)
CStdiofile and Seek(nBytes,CFile::current);
where nByte = 1

Now when I try to read the next character after 0xa, I find that the
offset has moved 1 byte extra.
For eg.
BG*test*test2*12345*1326*9150
GS*mytest*test4

Before GS the file contains 0xa (when viewed in hex editor)
Now when I try to read the next character after 0xa , I get 'S'
instead of 'G'

I don't quite follow. After you've read the end-of-line character, the
file pointer is positioned at G. You seek by one byte, so the file
pointer is now positioned at S. Why again do you expect to read G? Why
do you feel you need to seek in the first place?
--
With best wishes,
Igor Tandetnik

With sufficient thrust, pigs fly just fine. However, this is not
necessarily a good idea. It is hard to be sure where they are going to
land, and it could be dangerous sitting under them as they fly
overhead. -- RFC 1925


.



Relevant Pages

  • Re: Reading from a Random Access File
    ... the file pointer is now located at 2 ... public static void main ... a space character used as a field delimiter. ... int computerCount; ...
    (comp.lang.java.help)
  • Re: Offset by 1 in CStdiofile Seek while reading 0xa
    ... I am trying to read the file character by character until I encounter ... CStdiofile and Seek; ... where nByte = 1 ... file pointer is positioned at G. ...
    (microsoft.public.vc.language)
  • Re: Read Backwards in a text file
    ... much use in this regard. ... The problem with moving the file pointer in a text file is that you want to move to a specific character in the file, but the file pointer doesn't know about characters, it only knows about bytes. ... You could create your own line based stream reader that uses the fact that the line break is of a known size regardless of the encoding used. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: fwrite problem
    ... > I am updating a file by inserting date in it as a character string. ... i seek the file pointer to the proper ...
    (microsoft.public.vc.mfc)
  • Re: fwrite problem
    ... This character string is part of a structure and i am rewriting the whole structure into the file. ... Before updating the file, i seek the file pointer to the proper postion and also after updating the file, the file pointer is pointing to the overwritten character, next to structure. ...
    (microsoft.public.vc.language)