-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
43 lines (39 loc) · 1.42 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
39
40
41
42
43
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vopolonc <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/30 15:57:20 by vopolonc #+# #+# */
/* Updated: 2018/11/26 13:20:34 by vopolonc ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_return_res(unsigned long long n, int sign)
{
if (n > 9223372036854775807U && sign == 1)
return (-1);
if (n > 9223372036854775808U && sign == -1)
return (0);
else
return ((int)n * sign);
}
int ft_atoi(const char *str)
{
int i;
unsigned long long n;
int sign;
i = ft_skip(str);
n = 0;
sign = 1;
if (str[i] == '-')
sign *= -1;
((str[i] == '-' || str[i] == '+') ? i++ : i);
while (str[i] >= '0' && str[i] <= '9')
{
n = n * 10 + str[i] - '0';
i++;
}
return (ft_return_res(n, sign));
}