Condividi tramite


_StrCmp( ) API Library Routine

Compares each byte in two null-terminated strings, starting with the leftmost byte.

int _StrCmp(char FAR *string1, char FAR *string2)
char FAR *string1;         /* First comparison string. */
char FAR *string2;         /* Second comparison string. */

Remarks

_StrCmp( ) returns 0 if string1 and string2 match, a positive number if the first unmatched byte in string1 is greater than the corresponding byte in string2, or a negative number if the first unmatched byte in string1 is less than the corresponding byte in string2.

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 uses _StrCmp( ) to compare two strings passed as parameters.

Visual FoxPro Code

SET LIBRARY TO STRCMP  
? STRCMP("Hello, world.", "Hello, world.")  && matches; returns 0
? STRCMP("Hello, world.", "Hello, wurld.")  && no match; returns non-0

C Code

#include <pro_ext.h>

void NullTerminate(Value FAR *cVal)
{
   if (!_SetHandSize(cVal->ev_handle, cVal->ev_length + 1))
   {
      _Error(182); // "Insufficient memory"
   }
   ((char FAR *) _HandToPtr(cVal->ev_handle))[cVal->ev_length] = '\0';
}

FAR Example(ParamBlk FAR *parm)
{
   int RetValue;

   NullTerminate(&parm->p[0].val);
   NullTerminate(&parm->p[1].val);

   _HLock(parm->p[0].val.ev_handle);
   _HLock(parm->p[1].val.ev_handle);

   RetValue = _StrCmp(_HandToPtr(parm->p[0].val.ev_handle),
      _HandToPtr(parm->p[1].val.ev_handle));

   _RetInt(RetValue, 10); // does return control here

   _HUnLock(parm->p[0].val.ev_handle);
   _HUnLock(parm->p[1].val.ev_handle);
}

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

See Also

_StrCpy( ) API Library Routine | _StrLen( ) API Library Routine | _PutStr( ) API Library Routine | _WPutStr( ) API Library Routine | _SetHandSize( ) API Library Routine | String Manipulation Routines