@brief Convert raw null-terminated C-string to Fortran string
Note
No boundary checks for c-string are performed, use at your own risk!
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=c_char, len=1), | intent(in) | :: | cchar(*) |
function c_f_char(cchar) result(fstr) use, intrinsic :: iso_c_binding, only: c_char, c_null_char character(kind=c_char), intent(in) :: cchar(*) character(:), allocatable :: fstr integer :: i, strlen strlen = 0 do if (cchar(strlen+1) == c_null_char) exit strlen = strlen + 1 end do allocate(character(strlen) :: fstr) do i = 1, strlen fstr(i:i) = cchar(i) end do end function c_f_char