tgrekov-philosophers
HIVE philosophers July 2024
Loading...
Searching...
No Matches
atoi_errable.c
Go to the documentation of this file.
1
/* ************************************************************************** */
2
/* */
3
/* ::: :::::::: */
4
/* atoi_errable.c :+: :+: :+: */
5
/* +:+ +:+ +:+ */
6
/* By: tgrekov <tgrekov@student.hive.fi> +#+ +:+ +#+ */
7
/* +#+#+#+#+#+ +#+ */
8
/* Created: 2024/07/22 04:30:45 by tgrekov #+# #+# */
9
/* Updated: 2024/08/25 12:37:38 by tgrekov ### ########.fr */
10
/* */
11
/* ************************************************************************** */
12
28
int
atoi_errable
(
const
char
*str,
int
*n)
29
{
30
static
const
int
ft_int_max = 2147483647;
31
int
sign;
32
33
while
(*str ==
' '
|| *str ==
'\t'
|| *str ==
'\n'
34
|| *str ==
'\v'
|| *str ==
'\f'
|| *str ==
'\r'
)
35
str++;
36
sign = 1;
37
if
(*str ==
'-'
|| *str ==
'+'
)
38
{
39
if
(*str ==
'-'
)
40
sign *= -1;
41
str++;
42
}
43
*n = 0;
44
while
(*str >=
'0'
&& *str <=
'9'
)
45
{
46
if
(*n > ft_int_max / 10 || (*n == ft_int_max / 10 && *str >
'7'
))
47
return
(1);
48
*n = *n * 10 + (*(str++) -
'0'
);
49
}
50
*n = *n * sign;
51
return
(0);
52
}
atoi_errable
int atoi_errable(const char *str, int *n)
Converts ascii digits from str to a signed integer, output into n . Returns 0 on success,...
Definition
atoi_errable.c:28
src
mandatory
utils
atoi_errable.c