_MemFill( ) API Library Routine Example

The following example uses _MemFill( ) to duplicate the functionality of the Visual FoxPro function REPLICATE( ).

Visual FoxPro Code

SET LIBRARY TO MEMFILL 
x = xREPLICATE("x", 120)
? x
? LEN(x)

C Code

#include <pro_ext.h>

FAR Example(ParamBlk FAR *parm)
{
   char FAR *rep;
   char c = *(char *) _HandToPtr(parm->p[0].val.ev_handle);

   rep = _Alloca((int) parm->p[1].val.ev_long + 1);

   _MemFill(rep, c, (int) parm->p[1].val.ev_long);

  rep[parm->p[1].val.ev_long] = '\0';
   _RetChar(rep);
}
FoxInfo myFoxInfo[] = {
   {"XREPLICATE", (FPFI) Example, 2, "C,I"},
};
FoxTable _FoxTable = {
   (FoxTable FAR *) 0, sizeof(myFoxInfo)/sizeof(FoxInfo), myFoxInfo
};