Re: How to convert integers to characters?



"hermitian" <iamwuxin@xxxxxxxxx> wrote in message news:1191025165.820407.47400@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Is there any functions to convert integers to characters?

For example:
real::a=123.4 ! a is a real number
character(len=30)::b ! b is a character
!How can I convert a to b as a character, i.e. b would be 123.4, but b
is a character.

Moreover, is there any other functions can reverse the conversion?
i.e. from characters to numbers.

character(len=30)::b="123.4"
real::a

how can I assign 123.4 to a as a real number?

Many thanks!

In Fortran, you do not use functions for this operation, unlike in the C-like languages. Instead, you use "Internal I/O" statements, more specifically as "Internal Write" and "Internal Read" statements.

An internal read converts from character to binary. An internal write converts from binary to character.

Internal read and write statements work just like their counterparts that read from and write to external files. The only significant difference from the programmer's perspective is that you use a CHARACTER variable or array element in place of the Logical Unit Number (LUN). Everything else is the same, including format specifications and all of the other I/O keywords.

Using your example, here is what you would do:

Write (Unit=B, FMT="(F5.1)") A ! Converts value of A into CHARACTER variable B using F5.1 format edit descriptor.

Read (Unit=B, FMT=*) A ! Converts from CHARACTER variable B into REAL variable A using list-directed formatting.

Please read your Fortran documentation and/or textbook for further details on how this works.

--
Craig Dedo
17130 W. Burleigh Place
P. O. Box 423
Brookfield, WI 53008-0423
Voice: (262) 783-5869
Fax: (262) 783-5928
Mobile: (414) 412-5869
E-mail: <cdedo@xxxxxxxxx> or <craig@xxxxxxxxxx>

.



Relevant Pages

  • Prevent Blank Records being written. Need Help.
    ... Secondary record format is as follows: ... character text field, ... no input mask requirement ... allow zero length = yes. ...
    (microsoft.public.access.forms)
  • RE: Prevent Blank Records being written. Need Help.
    ... Secondary record format is as follows: ... > no input mask requirement ... > 30 character text field, ... > allow zero length = yes. ...
    (microsoft.public.access.forms)
  • Re: newbie question for reading input file
    ... Declarations are *VERY* important. ... feature is using a real variable to store character values. ... You have to use an explicit format with an appropriate "A" edit ... unused data edit descriptors at the end of the format are ignored, ...
    (comp.lang.fortran)
  • Re: txt-file is in ANSI format or OEM Character format.
    ... to automatically start the Ultraeditor from excel so the conversion is ... The older printers have a smaller character set ... Is it possibel, in VBA, to know if a txt-file is in ANSI format ...
    (microsoft.public.excel.programming)
  • Re: txt-file is in ANSI format or OEM Character format.
    ... Try 2 and 3 above changing formating to a different Font. ... This file I open in UltraEdit and change ANSI to OEM and close ... The older printers have a smaller character set it ... Character format. ...
    (microsoft.public.excel.programming)