I have to create a program that reverses phrases.
For example: when I write hello guys, I want syug olleh
This is what
@Rook's answer works for odd length of string too? Anyway here's my attempt, inspired by his answer which takes into account trailing blanks too:
! Reverse the string
function reverse_string(string) result(gnirts)
character(len=*) :: string
character(len(string)) :: gnirts
character(1) :: temp
integer :: i, length
length = len(string)
do i = 1,length
gnirts(length-i+1:length-i+1) = string(i:i)
end do
end function reverse_string