F_C_STRING (The GNU Fortran Compiler)

### 8.112 `F_C_STRING` — Convert Fortran character scalar to C string ¶

Synopsis:

  `RESULT = F_C_STRING(STRING[, ASIS])`

Description:

  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.

Class:

  Transformational function

Arguments:

  STRING | A character scalar of kind `C_CHAR`.
  ASIS | An optional logical scalar.

Return value:

  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.

Example:

      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

Standard:

  Fortran 2023 and later.

See also:

  `C_F_STRPOINTER` — Convert C string into Fortran string pointer