f_c_char Subroutine

public subroutine f_c_char(from, to, numchar)

Uses

  • proc~~f_c_char~~UsesGraph proc~f_c_char f_c_char iso_c_binding iso_c_binding proc~f_c_char->iso_c_binding

@brief Convert Fortran string to a raw null-terminated C-string

Note

No real boundary checks for c-string are performed, use at your own risk!

Note

C-string should be already allocated @param[in] from fortran string @param[out] to null-terminated c-string, len(to) should be at least numchar+1 @param[in] numchar maximum number of characters to pass from fortran to c-string

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: from
character(kind=c_char, len=1) :: to(*)
integer, intent(in) :: numchar

Source Code

  subroutine f_c_char(from, to, numchar)
    use, intrinsic :: iso_c_binding, only: c_char, c_null_char
    character(len=*), intent(in) :: from
    character(kind=c_char, len=1) :: to(*)
    integer, intent(in) :: numchar
    integer :: i
    do i = 1, min(len(from), numchar)
      to(i) = from(i:i)
    end do
    to(i) = c_null_char
  end subroutine f_c_char