Fortran Fortran: creating array containing characters

  • Thread starter Thread starter _Andreas
  • Start date Start date
  • Tags Tags
    Array Fortran
AI Thread Summary
To create an array of characters in a programming context, the initial attempt using a fixed dimension for the character array was unsuccessful. The correct approach involves defining a character string with a specified length and then populating a character array by iterating through each character of the string. The solution involves declaring a character variable for the string, an array for the characters, and using a loop to assign each character from the string to the array. This method effectively converts a string into a character array, allowing for better manipulation of individual characters.
_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?
 
Technology 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 camila
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I had a Microsoft Technical interview this past Friday, the question I was asked was this : How do you find the middle value for a dataset that is too big to fit in RAM? I was not able to figure this out during the interview, but I have been look in this all weekend and I read something online that said it can be done at O(N) using something called the counting sort histogram algorithm ( I did not learn that in my advanced data structures and algorithms class). I have watched some youtube...

Similar threads

Replies
4
Views
2K
Replies
6
Views
2K
Replies
16
Views
2K
Replies
13
Views
3K
Replies
4
Views
2K
Replies
8
Views
3K
Replies
18
Views
6K
Replies
11
Views
12K
Replies
13
Views
4K
Back
Top