xHarbour Reference Documentation > Function Reference |
Reads characters up to Chr(0) from a binary file.
FreadStr( <nFileHandle>, <nBytes> ) --> cString
The function returns the bytes read from the file as a character string. If an error occurs, a null string ("") is returned.
The low-level file function FReadStr() reads <nBytes> bytes from an open file and returns them as a character string. The file pointer is advanced by the number of bytes read. The function reads all bytes up to the end of file, except Chr(0). The bytes up to the first Chr(0), but not including Chr(0), are returned.
See also: | Bin2I(), Bin2L(), Bin2U(), Bin2W(), FClose(), FCreate(), FError(), FOpen(), FRead(), FSeek(), FWrite(), HB_FReadLine() |
Category: | File functions , Low level file functions |
Source: | rtl\philes.c |
LIB: | xhb.lib |
DLL: | xhbdll.dll |
// The example reads a file using FReadStr() and FRead() and // compares the results. #include "Fileio.ch" PROCEDURE Main LOCAL cBuffer LOCAL nHandle nHandle := FCreate( "Testfile.txt", FC_NORMAL ) FWrite( nHandle , "xHarbour" + Chr(0) + "compiler" ) FClose( nHandle ) nHandle := FOpen( "Testfile.txt" , FO_READ ) ? cBuffer := FReadStr( nHandle, 20 ) // result: xHarbour ? Len( cBuffer ) // result: 8 FSeek(nHandle, 0, FS_SET ) // go to begin of file cBuffer := Space( 20 ) ? FRead( nHandle, @cBuffer, 20 ) // result: 17 ? Trim( cBuffer ) // result: xHarbour compiler ? Asc( cBuffer[9] ) // result: 0 FClose( nHandle ) FErase( "Testfile.txt" ) RETURN
http://www.xHarbour.com