Embedded Artistry libc
C Standard Library Support for Bare-metal Systems
atoi.c
Go to the documentation of this file.
1
#include <
ctype.h
>
2
#include <
stdbool.h
>
3
#include <
stdlib.h
>
4
5
int
atoi
(
const
char
* str)
6
{
7
bool
neg =
false
;
8
int
val = 0;
9
10
switch
(*str)
11
{
12
case
'-'
:
13
neg =
true
;
14
// intentional fallthrough to advance str
15
case
'+'
:
16
str++;
17
}
18
19
while
(
isdigit
(*str))
20
{
21
val = (10 * val) + (*str++ -
'0'
);
22
}
23
24
return
(neg ? -val : val);
25
}
ctype.h
atoi
int atoi(const char *str)
Interprets an integer value in a byte string pointed to by str.
Definition:
atoi.c:5
stdlib.h
stdbool.h
isdigit
int isdigit(int ch)
Checks if the given character is a numeric character.
Definition:
isdigit.c:5
src
stdlib
atoi.c
Generated by
1.8.15