The C language does not have character strings. Instead, it has arrays of single characters, so this is how you must represent a character string in Fortran.
There is a kind value defined, C_CHAR, corresponding to the C char type. However, only character variables with a length of one (1) are interoperable.
The following shows a Fortran program passing a string to a C routine and the C routine calling a Fortran routine with a new string.
Fortran Program Example |
|---|
|
C Routine Example |
|---|
C module (c_append.c):
#include <string.h>
extern void fort_print(char * string); /* Fortran routine */
void c_append (char * string) {
char mystring[100];
strcpy(mystring, string);
strcat(mystring, " interoperates with C");
/* Call Fortran routine passing new string */
fort_print (mystring);
return;
} |