Convert a string coming from C into a Fortran string
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(kind=c_char), | intent(in) | :: | c_str(:) |
Input string to be converted |
||
character(len=*), | intent(out) | :: | f_str |
pure subroutine c2f_string(c_str, f_str)
!! Convert a string coming from C into a Fortran string
implicit none
character(kind=c_char), intent(in) :: c_str(:)
!! Input string to be converted
character(len=*), intent(out) :: f_str
integer :: i
i = 1
do while(c_str(i) /= c_null_char)
f_str(i:i) = c_str(i)
i = i + 1
end do
do i = i, len(f_str)
f_str(i:i) = ' '
end do
f_str = trim(f_str)
end subroutine c2f_string