Previous: Passing Strings Up: Passing Strings Next: Accepting C Strings in Fortran

Accepting Fortran Strings in C

Writing a C routine that accepts Fortran strings as arguments is not too difficult. Simply use the sfor2c (for input from a Fortran program) and sc2for (for output to a Fortran program) family of routines to convert the Fortran string into a C string and vice-versa.

The sfor2c and sc2for family of routines are described in Section , Fortran String Conversion Routines. There are examples in that section as well.

Typically, a Fortran to C bridge routine will first call some of the sfor2c routines to convert all the input strings to C format, then it will call the main C subroutine, and finally it will convert any output strings back to Fortran format via the sc2for family of routines.

There is no way currently implemented to return CHARACTER*n variables as the function return of a C subroutine. Any output strings should be included as arguments instead.

rgd059@ipl.jpl.nasa.gov