_FRead( ) API Library Routine 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
};