0

Out of interest, I was trying to find a way to cast an integer to a String in Fortran77. I came across CHAR(I), but this converts the ASCII index I into the character in that postion. Is there a way to just simply cast an integer to a String in Fortran77? How about vice versa?

1 Answer 1

3

The Fortran way is to write the value of the integer into a string variable; this operation is known as an internal write. I'm heading out the door now so won't check this, and I have an ethical objection to writing FORTRAN77 or helping anyone else write it, so make no guarantee that the following doesn't contain bits of more modern Fortran.

First declare a character variable to receive the integer

character(len=12) :: int_as_string

then write the integer into it as you would normally write an integer to any other channel such as stdout

write(int_as_string,'(i12.12)') my_int

I expect you'll want to set the format for writing the integer to something that suits you better

Sign up to request clarification or add additional context in comments.

2 Comments

yea I agree with you on the ethical objection part. thanks a lot!
what's the ethical objection? Is it just painful to code in? It's not like an environmental objection, is it? Like they have to chop down millions of trees for punch cards.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.