Syntax
ITEM *ACopy( const ITEM *source, ITEM *target, int start, int count, int targetPos );
Arguments
source, target Source and destination arrays.
start, targetPos One-based positions in the source and destination. NIL defaults to 1.
count Number of entries to copy. NIL copies as far as the source and destination lengths allow.
Return value
The destination array, or NULL if either argument is not an array.
Description
Copy into an existing array whose length determines how many values can fit. Copying stops at the end of either array. Positions outside the arrays or a count of zero or less, aside from the omitted-count value `NIL`, leave the destination unchanged.
Passing the same `ITEM` as both arguments supports overlapping ranges, so the call can shift values within one array. Copied subarrays remain shared. Use `AClone()` when each nested array needs independent storage.
Example
#include "xdev-wtui.h"
#include <stdio.h>
int main( void )
{
ITEM *source = Array( 3 );
ITEM *target = Array( 3 );
ITEM *status = ItemNew( NULL );
if( !source || !target )
{
ItemRelease( status );
ItemRelease( target );
ItemRelease( source );
return 1;
}
AFill( source, ItemPutC( status, "Ready" ), NIL, NIL );
AFill( target, ItemPutC( status, "Closed" ), NIL, NIL );
ACopy( source, target, NIL, 2, 2 );
for( int64_t i = 1; i <= ArrayLen( target ); ++i )
puts( ArrayGetCPtr( target, ( size_t )i ) );
ItemRelease( status );
ItemRelease( target );
ItemRelease( source );
return 0;
}
Output
Closed
Ready
Ready