Fortran: creating array containing characters

  • Context: Fortran 
  • Thread starter Thread starter _Andreas
  • Start date Start date
  • Tags Tags
    Array Fortran
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
1 reply · 22K views
_Andreas
Messages
141
Reaction score
1
Hello.

I'd like to create an array containing characters (basically a word stored as a 1xn array). I have no idea how to do this, however. I thought that the most obvious way to do it (yes, it would've been highly impractical for long words) was to write

character, dimension(3) :: A

A=[F,P,G]

but that doesn't work at all. Any suggestions?
 
Physics news on Phys.org
Ok, problem solved. If anyone's interested, this is how you do it:

character(len=n) :: string
character, dimension(n) :: array
integer :: i

string="blablabla and so on"

do i=1,len(string)
array(i)=string(i:i)
end do
 
  • Like
Likes   Reactions: camila