[<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _itemGetC()
 Retrieve a character value from an item
------------------------------------------------------------------------------
 C Prototype

     #include "item.api"
     BYTEP _itemGetC(
                      ITEM itmChar
                    )

 Arguments

     itmChar is the item from which to retrieve a character value.

 Returns

     A pointer to a copy of the string contained within itmChar.

 Description

     _itemGetC() returns a pointer to a copy of the character string or memo
     contained within itmChar.  If itmChar is not a character value (type
     MEMO or CHARACTER), the results will be unpredictable.

     Warning!  The pointer returned must be freed through an _itemFreeC()
     call.

 Examples

     /*
     *
     * CharCount( cString, cChar )
     *
     * Count occurrences of a single character
     * in a CA-Clipper string.
     *
     */

     CLIPPER CharCount( void )
     {
        USHORT uiChars = 0;
        USHORT uiLen;
        USHORT i;
        HANDLE vmhString;

        BYTEP  cStringP;
        BYTE   cFindMe;

        ITEM   itmString, itmFindMe, itmRet;

        if (PCOUNT != 2)
        {
           _ret();               // NOTE: Withhold service
           return;               // Early return!
        }

        itmRet    = _itemPutNL( NULL, 0 );
        itmString = _itemParam( 1 );
        itmFindMe = _itemParam( 2 );

        if ( (_itemType( itmString ) == CHARACTER) &&
              (_itemType( itmFindMe ) == CHARACTER) )
        {
           _itemCopyC( itmFindMe, &cFindMe, 1 );

           vmhString = _xvalloc( _itemSize( itmString ), NULL );
           cStringP = _xvlock( vmhString );

           uiLen = _itemCopyC( itmString, cStringP, NULL );

           for( i = 0; i < uiLen; i++ )
           {
              if ( cStringP[i] == cFindMe )
                 uiChars++;
           }

           _xvunlock( vmhString );
           _xvfree( vmhString );

           itmRet = _itemPutNL( itmRet, (long)uiChars );

        }

        _itemReturn( itmRet );

        _itemRelease( itmRet );
        _itemRelease( itmString );
        _itemRelease( itmFindMe );

        return;
     }

 Files  Library is CLIPPER.LIB, header file is Item.api.


See Also: _itemFreeC() _itemPutC() _itemPutCL()
This page created by ng2html v1.05, the Norton guide to HTML conversion utility. Written by Dave Pearson