-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi_long.c
37 lines (34 loc) · 1.24 KB
/
ft_atoi_long.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi_long.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: abassibe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/01/21 02:53:50 by abassibe #+# #+# */
/* Updated: 2018/03/14 04:18:42 by abassibe ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
long int ft_atoi_long(const char *str)
{
unsigned long int k;
int i;
long int ret;
int p;
k = 0;
i = 0;
while (ft_isspace(str[i]))
i++;
p = str[i] == '-' ? 1 : 0;
if (str[i] == '-' || str[i] == '+')
i++;
while (str[i] >= '0' && str[i] <= '9')
{
k *= 10;
k += str[i] - 48;
i++;
}
ret = p == 1 ? k * -1 : k;
return (ret);
}