-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
38 lines (36 loc) · 1.24 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
34
35
36
37
38
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: oel-yous <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/09 19:08:50 by oel-yous #+# #+# */
/* Updated: 2019/10/17 18:39:20 by oel-yous ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(char *str)
{
int signe;
unsigned long r;
while (*str >= 9 && *str <= 32)
str++;
signe = 1;
if (*str == '-')
{
signe = -1;
str++;
}
else if (*str == '+')
str++;
r = 0;
while (*str >= 48 && *str <= 57)
{
r = r * 10 + *str - '0';
if (r > 9223372036854775807)
return ((signe < 0) ? 0 : -1);
str++;
}
r = r * signe;
return (r);
}