Re: Conversion from int to char





Ron Ford wrote:
On Fri, 29 Aug 2008 14:52:52 -0700 (PDT), e p chandler posted:

Paul van Delst wrote:
michaelmetcalf@xxxxxxxxxxxxxx wrote:
On Aug 29, 4:28 pm, fm2766 <fm2...@xxxxxxxx> wrote:
Hello, I have to convert integers in characters; for example: from
number i=123456 to string c="123456".
I could write in a file the variable "i", and later read it as a
variable "c", but this method seems to me very inefficient.
Some suggestions?

Well, that's almost what you do, however, not to an external file but
to an 'internal' one as defined by your c, as in:

write(c, '(i6)') i

Maybe some thought should be given to giving this process an additional, more intuitive,
name. It's such a common question and "Internal file writing and reading" sure isn't the
first thing a newcomer thinks of when they want to convert int->character or vice versa.

Oh no. Let the C programmers learn some Fortran instead of whining
about it. Learning a foreign language involves learning its idioms. To
a FORTRAN programmer, the concept of "internal file" makes sense.

Gosh, elliot, I know that internal writes have been the answer for a lot of
questions I've had since I renewed my commitment to fortran as a syntax.
It's �9.6 in MR&C.

What I don't see is a file. By "file," do people mean "whatever internal
variables you used to read the data?"

Yes. I think of those variables as file buffers.

Also using internal files opens up the opportunity to have dynamic
format expressions. Since a format may be contained in a character
variable, it is possible to write to that character variable in a
creative way!

- e

[Aside] Back in ye olden days of interpreted Microsoft Basic, that
language (v4 and v5) had "PRINT USING" for formatted file output. But
it was not ordinarily possible to direct the output to a string, as is
done with sprintf in C. IIRC there was some way to get Basic to open a
file so that no external I/O actually took place. Instead it was
possible to access memory where the file contents would be placed. [/
Aside]


.



Relevant Pages

  • Re: Friday-afternoon
    ... glen herrmannsfeldt wrote: ... I believe this is still illegal in Fortran 2003, ... The internal file is required to be a variable, not a constant, ...
    (comp.lang.fortran)
  • Re: end-of-record versus end-of-file?
    ... > Is Mil-Std-1753 an official part of the Fortran 95 standard? ... It has the concept of endfile record. ... we are not reading an internal file. ...
    (comp.lang.fortran)
  • Re: Reintroduction to FORTRAN after >30 years
    ... I'm not aware of a Fortran FAQ... ... Probably the most general FAQ would be: ... for "internal file" in your Fortran Language Reference. ...
    (comp.lang.fortran)
  • Re: Reintroduction to FORTRAN after >30 years
    ... I'm not aware of a Fortran FAQ... ... Stop trying to find the intrinsic "Num2Str", ... for "internal file" in your Fortran Language Reference. ...
    (comp.lang.fortran)