A Collection of Code Snippets in as Many Programming Languages as Possible
This project is maintained by TheRenegadeCoder
Welcome to the Reverse String in Fortran page! Here, you'll find the source code for this program as well as a description of how the program works.
program reverse_string
implicit none
character(len=:), allocatable :: arg, rev
integer :: i, n, error
if (command_argument_count() < 1) then
print '("")'
stop
end if
! Get length of argument
call get_command_argument(1, length=n, status=error)
if (error /= 0 .or. n == 0) then
print '("")'
stop
end if
! Allocate and read argument
allocate(character(len=n) :: arg)
call get_command_argument(1, arg, status=error)
if (error /= 0) then
print '("")'
deallocate(arg)
stop 0
end if
! Allocate and create reversed string
allocate(character(len=n) :: rev)
do i = 1, n
rev(i:i) = arg(n-i+1:n-i+1)
end do
print '(A)', rev
end program reverse_string
Reverse String in Fortran was written by:
If you see anything you'd like to change or update, please consider contributing.
No 'How to Implement the Solution' section available. Please consider contributing.
No 'How to Run the Solution' section available. Please consider contributing.