Compartir a través de


_FRead( ) API Library Routine

Copies to the buffer exactly length bytes from a file into buffer.

unsigned int _FRead(FCHAN chan, char FAR *buffer, int length)
FCHAN chan;               /* File channel of file from which to copy. */
char FAR *buffer;            /* Buffer address. */
int length;                  /* Number of bytes to be copied. */

Remarks

_FRead( ) doesn't add a terminator to the end of the bytes in the buffer. No translation is performed on the bytes when they are stored in the buffer. _FRead( ) returns the number of bytes read.

For more information on how to create an API library and integrate it with Visual FoxPro, see Accessing the Visual FoxPro API.

Example

The following example creates a test file and places text in it. The example then attempts to read 32 bytes from the file using _FRead( ).

Visual FoxPro Code

SET LIBRARY TO FREAD 

C Code

#include <pro_ext.h>

#define BUFFSIZE 32
static char buffer[BUFFSIZE];

FAR Example(ParamBlk FAR *parm)
{
   FCHAN fchan;
   int bytesRead;

   fchan = _FCreate("temp.tmp", FC_NORMAL);
   _FPuts(fchan, "Hello, world.");
   _FPuts(fchan, "Hello, world.");
   _FPuts(fchan, "Hello, world.");
   _FPuts(fchan, "Hello, world.");
   _FPuts(fchan, "Hello, world.");

   _FSeek(fchan, 0, FS_FROMBOF);

   bytesRead = _FRead(fchan, buffer, BUFFSIZE - 1);
   buffer[bytesRead] = '\0';
   _PutStr(buffer);

   _FClose(fchan);
}

FoxInfo myFoxInfo[] = {
   {"FREAD", (FPFI) Example, CALLONLOAD, ""},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};

See Also

_FGets( ) API Library Routine | _FSeek( ) API Library Routine | Accessing the Visual FoxPro API