-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atol.c
38 lines (35 loc) · 1.27 KB
/
ft_atol.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_atol.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rlechapt <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/02/02 16:28:33 by rlechapt #+# #+# */
/* Updated: 2015/02/02 16:36:21 by rlechapt ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
long ft_atol(const char *str)
{
int i;
int sign;
long val;
i = 0;
sign = 1;
val = 0;
while (((str[i] >= 9 && str[i] <= 13) || str[i] == 32) && str[i])
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
sign = -1;
i++;
}
while (str[i] >= '0' && str[i] <= '9' && str[i] != '\0')
{
val = (val * 10) + (str[i] - 48);
i++;
}
return (val * sign);
}