A string variable generates two pointers. The first points to the string data structure and the second points to the dimension table. For simple strings only the element length is defined in the dimension structure. It specifies the maximum dimensioned length of the string data.
This example sets a simple string variable from a C routine.
BASIC Program
10 DIM S$[40]
20 CALL Strint( S$ )
30 PRINT LEN(S$),S$
40 END
50 SUB Strint( A$ )
60 A$ = "This is a test of strings"
70 SUBEND
Prototype
1 END
10 SUB Strint( A$ )
20 SUBEND
C Program
#include "csub.h"
#include <string.h>
strint( npar, a, d )
int npar; /* number of parameters */
strptr a; /* string data pointer */
dimptr d; /* string dimension pointer */
{
if( d->elen < 25 ) /* check variable length */
return( 18 ); /* too small, return error */
memcpy( a->str, "This is a test of strings", 25);
a->clen = 25; /* set the length */
return( 0 ); /* no error */
}
Note: if the strcpy( ) function is used, remember that it will append a NULL.