-
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: ana-lda- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/26 13:19:55 by ana-lda- #+# #+# */
/* Updated: 2024/07/08 16:49:02 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
long ft_atol(const char *str)
{
int i;
int neg;
long number;
i = 0;
neg = 1;
number = 0;
while (str[i] != '\0' && ((str[i] <= 13 && str[i] >= 9) || str[i] == ' '))
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
neg = -1;
i++;
}
while (str[i] >= 48 && str[i] <= 57)
{
number = (number * 10) + (str[i] - 48);
i++;
}
return (number * neg);
}