-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
33 lines (31 loc) · 1.27 KB
/
ft_atoi.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: albarret <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/11/05 15:35:20 by albarret #+# #+# */
/* Updated: 2018/11/12 21:35:40 by albarret ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *str)
{
long int res;
int negative;
negative = 1;
res = 0;
while (*str && (*str == ' ' || *str == '\n' || *str == '\t' ||
*str == '\v' || *str == '\f' || *str == '\r'))
++str;
if (*str == '-')
negative = -1;
if (*str == '-' || *str == '+')
++str;
while (*str && *str >= '0' && *str <= '9')
{
res = res * 10 + (*str - 48);
++str;
}
return (res * negative);
}