Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29265 Discussions

amateur question about characters and integers

ioanna
Beginner
735 Views
my question is if there is a command and how can i change an integer to the same character??? ie if
character fname and i=5, fname=command(i)='5'

thanx...

ioanna
0 Kudos
4 Replies
Steven_L_Intel1
Employee
735 Views
In most cases, when programmers ask how to convert between character representations of numbers and numeric representations in Fortran, the answer is "internal file I/O", such as internal READ or WRITE. This lets you read from a character variable as if it were a record in a file, or write to a character variable.

In some cases with single characters, you might find the CHAR and ICHAR intrinsics to be useful, but note that these convert between the internal binary representation, so you need to do something like:

i = ichar('5') - ichar('0')

to convert '5' to 5.

Steve
0 Kudos
elainethale
Beginner
735 Views
If I understand you correctly, the posted reply did not answer your question -- you wanted to convert from integer TO character, not the other way around. I would like to do the same thing -- did you ever find a function to do that?

Thank you,
Elaine Hale
0 Kudos
Steven_L_Intel1
Employee
735 Views
Elaine, welcome to the forum. Please note that the original post was over a year ago.

My response DID answer the question, for both directions. To convert from numeric to character, use internal WRITE. To convert from character to numeric, use internal READ. Both of these topics are discussed in the Language Reference Manual.

Steve
0 Kudos
elainethale
Beginner
735 Views
Oh -- I see -- I thought the first paragraph of your reply was leading up to the second, but it stands on its own -- sorry!

Elaine
0 Kudos
Reply