@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
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | from | |||
character(kind=c_char, len=1) | :: | to(*) | ||||
integer, | intent(in) | :: | numchar |
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