Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- CA-Clipper 5.2 . Technical Reference - <b>_itemcopyc()</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
 _itemCopyC()
 Copy a character Item's value into a C buffer
------------------------------------------------------------------------------
 C Prototype

     #include "item.api"
     USHORT _itemCopyC(
                        ITEM itemChar,
                        BYTEP fpBuffer,
                        USHORT uiSize
                      )

 Arguments

     itemChar is the Item from which to get a character value.

     fpBuffer is the preallocated buffer to copy the item's value into.

     uiSize is fpBuffer's size (one-based).  If this parameter is zero,
     _itemCopyC() will assume that the buffer is of adequate size to hold the
     string.

 Returns

     The number of characters copied into the character buffer.

 Description

     The _itemCopyC() function copies an item's character value into a buffer
     of uiSize length.  This is useful when you need to be in control of
     allocation and deallocation of the buffer used for the item's value.

     Warning!  You are responsible for allocating and freeing a buffer of
     adequate size for the Item.  There is no need to call _itemFreeC()
     when using _itemCopyC() as with _itemGetC().

 Examples

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

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

        BYTEP  cStringP;
        BYTE   cFindMe;

        ITEM   itemString, itemFindMe, itemRet;

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

        itemRet    = _itemPutNL( NULL, 0 );
        itemString = _itemParam( 1 );
        itemFindMe = _itemParam( 2 );

        if ( (_itemType( itemString ) == CHARACTER) &&
              (_itemType( itemFindMe ) == CHARACTER) )
        {
           _itemCopyC( itemFindMe, &cFindMe, 1 );

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

           uiLen = _itemCopyC( itemString, cStringP, NULL );

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

           _xvunlock( vmhString );
           _xvfree( vmhString );

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

        }

        _itemReturn( itemRet );

        _itemRelease( itemRet );
        _itemRelease( itemString );
        _itemRelease( itemFindMe );

        return;
     }

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


See Also: _itemGetC()

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson