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
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.

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