F_C_STRING — Convert Fortran character scalar to C string ¶RESULT = F_C_STRING(STRING[, ASIS])
The F_C_STRING intrinsic is equivalent to STRING//C_NULL_CHAR
if the ASIS argument is present and true, and to
TRIM(STRING)//C_NULL_CHAR otherwise.
Transformational function
| STRING | A character scalar of kind C_CHAR. |
| ASIS | An optional logical scalar. |
The result is a null-terminated character scalar of the same type and kind
as STRING, suitable for passing to a C function that accepts a
char * argument.
program main
use iso_c_binding, only: f_c_string, c_char
implicit none (external, type)
character(:, c_char), allocatable :: s1, s2, s3
! s1 is null-terminated "hello, world! "
s1 = f_c_string ("hello, world! ", .true.)
! s2 is null-terminated "hello, world!"
s2 = f_c_string ("hello, world! ", .false.)
! s3 is null-terminated "hello, world!" (same as s2 example)
s3 = f_c_string ("hello, world! ")
end program main
Fortran 2023 and later.
C_F_STRPOINTER — Convert C string into Fortran string pointer