Next: , Previous: IACHAR, Up: Intrinsic Procedures


8.68 ICHAR — Character-to-integer conversion function

Description:
ICHAR(C) returns the code for the character in the first character position of C in the system's native character set. The correspondence between character and their codes is not necessarily the same between GNU Fortran implementations.
Option:
f95, gnu
Class:
elemental function
Syntax:
I = ICHAR(C)
Arguments:

C Shall be a scalar CHARACTER, with INTENT(IN)

Return value:
The return value is of type INTEGER and of the default integer kind.
Example:
          program test_ichar
            integer i
            i = ichar(' ')
          end program test_ichar
     

Note:
No intrinsic exists to convert a printable character string to a numerical value. For example, there is no intrinsic that, given the CHARACTER value 154, returns an INTEGER or REAL value with the value 154.

Instead, you can use internal-file I/O to do this kind of conversion. For example:

          program read_val
            integer value
            character(len=10) string
          
            string = '154'
            read (string,'(I10)') value
            print *, value
          end program read_val