-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atol.c
40 lines (37 loc) · 1.33 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
39
40
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atol.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rabougue <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2015/11/25 10:57:59 by rabougue #+# #+# */
/* Updated: 2016/06/10 14:45:20 by rabougue ### ########.fr */
/* */
/* ************************************************************************** */
#include "./includes/libft.h"
long ft_atol(const char *str)
{
unsigned long i;
unsigned long out;
unsigned long j;
j = 0;
out = 0;
i = 0;
while (str[i] == ' ' || str[i] == '\t' || str[i] == '\n'
|| str[i] == '\r' || str[i] == '\v' || str[i] == '\f')
{
i++;
j++;
}
if (str[i] == '+' || str[i] == '-')
i++;
while (str[i] >= '0' && str[i] <= '9')
{
out = out * 10 + str[i] - '0';
i++;
}
if (str[j] == '-')
out = out * -1;
return (out);
}