program f90_CHAR_SORT implicit none integer,parameter::nn=1000,mm=100 character(len=mm)::str(1:nn) integer::i,io,nd character(len=50)::fnameR,fnameW call getarg(1,fnameR) call getarg(2,fnameW) open(11,file=fnameR,status='old') do i=1,nn read(11,'(a)',iostat=io) str(i) if(io<0)exit end do close(11) nd=i-1 call CHAR_SORT(nd,str) open(12, file=fnameW, status='replace') do i=1,nd write(12,'(a)') trim(adjustl(str(i))) end do close(12) stop contains subroutine CHAR_SORT(nd,string) integer,intent(in)::nd character(len=*),intent(inout)::string(:) character(len=len(string))::tmp integer::i,j do i=1,nd-1 do j=i+1,nd if(string(i)>string(j))then tmp=string(j) string(j)=string(i) string(i)=tmp end if end do end do end subroutine CHAR_SORT end program f90_CHAR_SORT