Low level

Posted: 2017-01-19 in Low level

FSEEK() is actually moving the pointer. If I do the following I get the expected results except that BOF() doesn’t return True even before I move through the file.
Using FGETS(<fd>,0,1) appears to correctly return the current position:

Code:
open database southwind
use customers
copy to xxx.txt type csv
xxx=fopen("xxx.txt")
? xxx
? bof()
? fseek(xxx,0,1)
? fgets(xxx)
? fseek(xxx,0,1)
? fseek(xxx,0,0)
? fseek(xxx,0,1)

The FEOF() flag only gets set/reset after a read operation. As Dave says, the fseek(FileHandle,0,0) is returning you to the start of the file, it’s just that having been set, FEOF() won’t be unset until you do another read operation. Try something like this:

Code:
FileHandle = FOPEN(Lianja.Get("Gamesheet.GSHeader.txtGamesheet").text)

Do While .T.
  cGetline = fgets(FileHandle)
  If FEOF(FileHandle)
    exit
  else
    // process ...
  endif
ENDDO

fseek(FileHandle,0,0)  // Return to start of file

Do While .T.
  cGetline = fgets(FileHandle)
  If FEOF(FileHandle)
    exit
  else
    // process ...
  endif
ENDDO


Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s