Convert a c_ptr
to a string into a Fortran string.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
type(c_ptr), | intent(in) | :: | cp | |||
character(len=:), | intent(out), | allocatable | :: | fstr |
subroutine c_ptr_to_f_string(cp,fstr) implicit none type(c_ptr),intent(in) :: cp character(len=:),allocatable,intent(out) :: fstr integer :: ilen !! string length ilen = strlen(cp) block !convert the C string to a Fortran string character(kind=c_char,len=ilen+1),pointer :: s call c_f_pointer(cp,s) fstr = s(1:ilen) nullify(s) end block end subroutine c_ptr_to_f_string