libft
src
ft_atoi.c
Go to the documentation of this file.
1
/* ************************************************************************** */
3
/* */
4
/* ::: :::::::: */
5
/* ft_atoi.c :+: :+: :+: */
6
/* +:+ +:+ +:+ */
7
/* By: unite <marvin@42.fr> +#+ +:+ +#+ */
8
/* +#+#+#+#+#+ +#+ */
9
/* Created: 2019/09/04 23:56:29 by unite #+# #+# */
10
/* Updated: 2020/07/16 03:05:43 by unite ### ########.fr */
11
/* */
12
/* ************************************************************************** */
13
14
#include "
libft.h
"
15
#include <limits.h>
16
21
int
ft_atoi
(
const
char
*str)
22
{
23
int
i;
24
int
num;
25
int
is_neg;
26
27
i = 0;
28
is_neg = 0;
29
num = 0;
30
while
(str[i] ==
' '
|| str[i] ==
'\t'
|| str[i] ==
'\n'
|| str[i] ==
'\v'
31
|| str[i] ==
'\f'
|| str[i] ==
'\r'
)
32
i++;
33
if
(str[i] ==
'-'
)
34
is_neg = 1;
35
if
(str[i] ==
'-'
|| str[i] ==
'+'
)
36
i++;
37
while
(str[i] >=
'0'
&& str[i] <=
'9'
)
38
{
39
num *= 10;
40
num += (str[i] -
'0'
);
41
i++;
42
}
43
return
(is_neg ? -num : num);
44
}
libft.h
ft_atoi
int ft_atoi(const char *str)
Replicates behaviour of atoi from libc.
Definition:
ft_atoi.c:21
Generated by
1.8.16