Syntax
ITEM *ADel( ITEM *array, int position );
Arguments
array Array to edit.
position One-based position of the element to remove.
Return value
The array, or NULL if array is not an array.
Description
Remove the value at a one-based position and shift the following values one slot toward the start. The array keeps its length and its final slot becomes `NIL`. This makes it possible to remove a value from a fixed-size list.
To reduce the length as well, call `ASize()` after the deletion. An out-of-range position leaves the array unchanged.
Example
#include "xdev-wtui.h"
#include <stdio.h>
int main( void )
{
ITEM *array = Array( 3 );
if( !array )
return 1;
ArraySetNI( array, 1, 1 );
ArraySetNI( array, 2, 2 );
ArraySetNI( array, 3, 3 );
ADel( array, 2 );
printf( "After deletion: %d %d %s\n", ArrayGetNI( array, 1 ),
ArrayGetNI( array, 2 ), ItemType( ATail( array ) ) == IT_NIL ? "NIL" : "value" );
ASize( array, 2 );
printf( "After shrinking: %d %d\n", ArrayGetNI( array, 1 ), ItemGetNI( ATail( array ) ) );
ItemRelease( array );
return 0;
}
Output
After deletion: 1 3 NIL
After shrinking: 1 3