Next: POINTER Arrays
Up: More on Arrays
Previous: CHARACTER and LOGICAL Arrays
Arrays of pointer to char
In C, arrays of character strings are often held as arrays of
pointer to char.
This allows strings of varying length and not necessarily in contiguous
memory.
CNF functions
cnfImprtap
and
cnfExprtap
can be used to import/export arrays of pointer to char from/to
FORTRAN CHARACTER arrays.
The following example shows how to do this. The FORTRAN subroutine, PRARR,
prints the given CHARACTER array and returns it set to blank strings.
The C program prints the strings before and after the call to PRARR.
Example
- IMPORT/EXPORT with arrays of pointers to char.
rlsaxp_101% more temp.c
#include "f77.h"
F77_SUBROUTINE(prarr)(CHARACTER_ARRAY(arr) TRAIL(arr));
main() {
DECLARE_CHARACTER_ARRAY(arr,12,3);
char *ptr[3]={"ajc","hello there","TEXT"};
int dims[1]=3;
int i;
for (i=0;i<3;i++) printf("%d:%s:\n",i,ptr[i]);
cnfExprtap(ptr,arr[0],12,1,dims);
F77_CALL(prarr)(CHARACTER_ARRAY_ARG(arr) TRAIL_ARG(arr));
cnfImprtap(arr[0],12,ptr,1,1,dims);
for(i=0;i<3;i++) printf("%d:%s:\n",i,ptr[i]);
}
SUBROUTINE PRARR( ARR )
CHARACTER*(*) ARR(3)
INTEGER I
DO 10
PRINT *, ':', ARR(I), ':'
ARR( I ) = ' '
10 CONTINUE
END
Next: POINTER Arrays
Up: More on Arrays
Previous: CHARACTER and LOGICAL Arrays
CNF and F77 Mixed Language Programming -- FORTRAN and C
Starlink User Note 209
P.M. Allan
A.J. Chipperfield
R.F. Warren-Smith
19 January 2000
E-mail:ussc@star.rl.ac.uk