I have to create a program that reverses phrases.
For example: when I write hello guys
, I want syug olleh
This is what
Well, of course we want to be able to do this via a constant expression, so we attempt the following:
program reverse
implicit none
character(20), parameter :: input = 'Forward'
integer i
character(len(input)), parameter :: output = &
transfer([(input(i:i),i=len_trim(input),1,-1)],trim(input))
write(*,'("#",a,"#")') input, output
end program reverse
We get the same output with both gfortran and ifort:
#Forward #
#drawroF#
I can't see what I might be doing wrong... is it the same bug in both compilers?