-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atol.c
More file actions
36 lines (33 loc) · 1.2 KB
/
ft_atol.c
File metadata and controls
36 lines (33 loc) · 1.2 KB
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: sudaniel <sudaniel@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/30 07:24:41 by sudaniel #+# #+# */
/* Updated: 2024/12/09 13:09:25 by sudaniel ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
long ft_atol(const char *str)
{
long num;
int sign;
num = 0;
sign = 1;
while ((*str >= 9 && *str <= 13) || *str == ' ')
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign = -1;
str++;
}
while ('0' <= *str && *str <= '9')
{
num *= 10;
num += *str++ - '0';
}
return (sign * num);
}