Convert a Fortran string to a c_ptr
to a string.
(the C string must already have been allocated to a fixed size)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | fstr | |||
type(c_ptr), | intent(inout) | :: | buffer |
a preallocated string buffer |
subroutine f_string_to_c_ptr(fstr,buffer) implicit none character(len=*),intent(in) :: fstr type(c_ptr),intent(inout) :: buffer !! a preallocated string buffer integer :: ilen !! string length of buffer ilen = strlen(buffer) block character(kind=c_char,len=ilen+1),pointer :: s call c_f_pointer(buffer,s) s(1:min(len(fstr),ilen)) = fstr(1:min(len(fstr),ilen)) buffer = c_loc(s) end block end subroutine f_string_to_c_ptr