Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Fortran: creating array containing characters

  1. Jul 27, 2010 #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?
     
  2. jcsd
  3. Jul 28, 2010 #2
    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
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Fortran: creating array containing characters
Loading...