Functions

AFill

Fill all or part of an array with one value

Syntax

Signature
ITEM *AFill( ITEM *array, const ITEM *value, int start, int count );

Arguments

array Array to fill.

value Value to copy into each selected slot. NULL fills with NIL elements.

start First position to fill, counted from 1. NIL defaults to 1.

count Number of entries to fill. NIL fills through the end of the array.

Return value

The array, or NULL if array is not an array.

Description

Assign the same value to each slot in the requested range while keeping the array's length. Filling stops at the end of the array. A start outside the array or a count of zero or less, aside from the omitted-count value `NIL`, leaves it unchanged.

Filling acts on the selected dimension. If the assigned value is an array, each filled slot refers to that same array. For independent values inside nested rows, fill each row separately.

Example

afill.c
#include "xdev-wtui.h"

#include <stdio.h>

int main( void )
{
   ITEM *completed = Array( 3 );
   ITEM *flag = ItemNew( NULL );

   if( !completed )
   {
      ItemRelease( flag );
      return 1;
   }

   AFill( completed, ItemPutL( flag, F ), NIL, NIL );
   AFill( completed, ItemPutL( flag, T ), 2, 2 );

   for( size_t i = 1; i <= 3; ++i )
      printf( "Task %zu: %s\n", i, ArrayGetL( completed, i ) ? "complete" : "pending" );

   ItemRelease( flag );
   ItemRelease( completed );

   return 0;
}

Output

Task 1: pending
Task 2: complete
Task 3: complete

See also