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

FREADSTR() 1

Status
Not open for further replies.

SM777

Technical User
Mar 7, 2001
208
GB
How do I determine when I'm at the end of a file with FREADSTR()?

I want to read in a file one character at a time in a do while loop. How do I tell when I have reached the last character?

 
Refer to NG for Clipper, or the Clipper manuals. Normally, freadstr() returns NULL when the size of the buffer you send "by reference (@)" to this function, exceeds the remaning bytes of the file. Usuallly the EOF() of a file is CHR(26), but not expect this always will work.

I use to manage this situation with fread() (nearly identical with freadstr() ), and check if in the buffer I read there is a chr(26), or null response, or the size of the response isn't identical that the buffer I've sent to read.
In this case, simply check for the len() of the buffer: if is different against the size of the buffer you sent, you reached the eof().
 
Use before the FSeek() function to determine the length of file and test the readed bytes in your loop.
 
To expand on what JMike posted, do the following -

nHandle := fopen( <file> )
nSize := fseek( nHandle, 0, 2 ) // gets the size of the file
fseek( nHandle, 0, 0 ) // reposition to the begining
do while ( fseek( nHandle, 0, 1 ) <= nSize )
<Your Loop>
enddo

This always worked for me.
 
Ok, that sounds good.

But the filesize is about 500Kb, I see in the norton guides that there could be a limit of 64K.

Havent tried it yet. Guess I need to see if it will work with that sized file.
 
The 64K limit is for the number of characters that can be read at one time. It does not refer to the file size. I have openned files that are over 1Meg is size and move around in them without any trouble. Just make sure you move around in the large files in blocks less than 64K.
 
The fxxxx files functions have the DOS operating system limits. (fxxx functions == INT 21 DOS functions)

Only the strings are limited to 64k (a physical memory page).

Manage the file in buffers or arrays using a file pointer
obtained with fseek() function.

I use this technique for compressing and sending large files.

If you need a help in this way email me to:

JMG
dds@andorra.ad
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top