xHarbour Reference Documentation > Function Reference xHarbour Developers Network  

FReadStr()

Reads characters up to Chr(0) from a binary file.

Syntax

FreadStr( <nFileHandle>, <nBytes> ) --> cString

Arguments

<nFileHandle>
This is a numeric file handle returned from function FOpen() or FCreate().
<nBytes>
This is a numeric value specifying the number of bytes to read from the file, beginning at the current file pointer position.

Return

The function returns the bytes read from the file as a character string. If an error occurs, a null string ("") is returned.

Description

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.

Info

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

Example

// 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

Copyright © 2006-2007 xHarbour.com Inc. All rights reserved.
http://www.xHarbour.com
Created by docmaker.exe