-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atol.c
36 lines (33 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atol.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atoof <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/11 17:32:52 by atoof #+# #+# */
/* Updated: 2023/04/11 18:04:00 by atoof ### ########.fr */
/* */
/* ************************************************************************** */
#include "push_swap.h"
long ft_atol(const char *str)
{
int i;
long n;
int sign;
i = 0;
n = 0;
sign = 1;
while ((str[i] >= 9 && str[i] <= 13) || str[i] == ' ')
i++;
if (str[i] == '-')
sign = sign * -1;
if (str[i] == '+' || str[i] == '-')
i++;
while (str[i] >= '0' && str[i] <= '9')
{
n = (n * 10) + str[i] - '0';
i++;
}
return (n * sign);
}