HTBasic Help
×
Menu
Index

Numeric Arrays

 
A numeric array variable generates two pointers. The first points to the first element of the data array and the second points to the array dimension table. The array elements are stored in row-major order.
 
This example shows how to access an INTEGER array from a C routine.
 
BASIC Program
10  INTEGER I(20),S
20  MAT I=(2)
30  CALL Isum( I(*),S )
40  PRINT S
50  END
60  SUB Isum( INTEGER A(*), S )
70   S=0
80   FOR I=0 to 20
90     S=S+A(I)
100  NEXT I
110 SUBEND
 
Prototype
1  END
10 SUB Isum( INTEGER A(*), S )
20 SUBEND
 
C Program
#include "csub.h"
isum( npar, a, d, s )   /* sum integer array */
int npar; /* number of parameters */
intptr a;             /* array data pointer */
dimptr d;             /* array dim entry pointer */
intptr s;             /* integer sum pointer */
{
int i;                /* element counter */
int max = d->cae;    /* get number of elements */
int sum = 0L;         /* clear the sum */
 
for(i = 0; i < max; ++i) /* scan all elements */
 sum += a[i];
*s = (T_INT)sum;      /* return the sum value */
return( 0 );          /* no error */
}