]> git.ipfire.org Git - thirdparty/gcc.git/blame - gcc/fortran/doc/gfortran/intrinsic-procedures/ichar.rst
sphinx: add missing trailing newline
[thirdparty/gcc.git] / gcc / fortran / doc / gfortran / intrinsic-procedures / ichar.rst
CommitLineData
c63539ff
ML
1..
2 Copyright 1988-2022 Free Software Foundation, Inc.
3 This is part of the GCC manual.
4 For copying conditions, see the copyright.rst file.
5
6.. _ichar:
7
8.. index:: ICHAR
9
10.. index:: conversion, to integer
11
12ICHAR --- Character-to-integer conversion function
13**************************************************
14
15.. function:: ICHAR(C)
16
17 ``ICHAR(C)`` returns the code for the character in the first character
18 position of ``C`` in the system's native character set.
19 The correspondence between characters and their codes is not necessarily
20 the same across different GNU Fortran implementations.
21
22 :param C:
23 Shall be a scalar ``CHARACTER``, with ``INTENT(IN)``
24
25 :param KIND:
26 (Optional) An ``INTEGER`` initialization
27 expression indicating the kind parameter of the result.
28
29 :return:
30 The return value is of type ``INTEGER`` and of kind :samp:`{KIND}`. If
31 :samp:`{KIND}` is absent, the return value is of default integer kind.
32
33 Standard:
34 Fortran 77 and later, with :samp:`{KIND}` argument Fortran 2003 and later
35
36 Class:
37 Elemental function
38
39 Syntax:
40 .. code-block:: fortran
41
42 RESULT = ICHAR(C [, KIND])
43
44 Example:
45 .. code-block:: fortran
46
47 program test_ichar
48 integer i
49 i = ichar(' ')
50 end program test_ichar
51
52 Specific names:
53 .. list-table::
54 :header-rows: 1
55
56 * - Name
57 - Argument
58 - Return type
59 - Standard
60
61 * - ``ICHAR(C)``
62 - ``CHARACTER C``
63 - ``INTEGER(4)``
64 - Fortran 77 and later
65
66 Note:
67 No intrinsic exists to convert between a numeric value and a formatted
68 character string representation -- for instance, given the
69 ``CHARACTER`` value ``'154'``, obtaining an ``INTEGER`` or
70 ``REAL`` value with the value 154, or vice versa. Instead, this
71 functionality is provided by internal-file I/O, as in the following
72 example:
73
74 .. code-block:: fortran
75
76 program read_val
77 integer value
78 character(len=10) string, string2
79 string = '154'
80
81 ! Convert a string to a numeric value
82 read (string,'(I10)') value
83 print *, value
84
85 ! Convert a value to a formatted string
86 write (string2,'(I10)') value
87 print *, string2
88 end program read_val
89
90 See also:
91 :ref:`ACHAR`,
92 :ref:`CHAR`,
3ed1b4ce 93 :ref:`IACHAR`