Manual Reference Pages  - atoi (3m_strings)

NAME

atoi(3f) - [M_strings:TYPE] function returns a 32-bit integer value from a string (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Returns
Examples
Author
License

SYNOPSIS

pure elemental function atoi (string) result(val)

    character(len=*),intent(in)      :: string
    integer(kind=int32),intent(out)  :: val

DESCRIPTION

function atoi(3f) converts a string representing an integer value to a numeric 32-bit integer value.

OPTIONS

str holds string assumed to represent a numeric integer value

RETURNS

val returned INTEGER.

EXAMPLES

Sample Program:

     program demo_atoi

use iso_fortran_env, only: wp => int32 use M_strings, only: atoi implicit none character(len=14),allocatable :: strings(:) integer(kind=wp) :: iv integer :: i

! different strings representing whole numbers strings=[& &’+10 ’,& &’ -3 ’,& &’ ’,& ! Note: will return zero without an error message &’1 2 1 2 1 . 0 ’,& ! Note: will just read first value &’WHAT? ’] ! Note: will return zero without an error message

do i=1,size(strings) iv=atoi(strings(i)) write(*,’(*(g0,1x))’)’STRING:’,strings(i),’:VALUE:’,iv enddo

end program demo_atoi

Results:

 > STRING: +10            :VALUE: 10
 > STRING:     -3         :VALUE: -3
 > STRING:                :VALUE: 0
 > STRING: 1 2 1 2 1 . 0  :VALUE: 1
 > STRING: WHAT?          :VALUE: 0

AUTHOR

John S. Urban

LICENSE

Public Domain


Nemo Release 3.1 atoi (3m_strings) January 10, 2025
Generated by manServer 1.08 from b0731e12-614f-4dc6-acd3-a9f3cade15b3 using man macros.