-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathft_atoll.c
49 lines (44 loc) · 1.45 KB
/
ft_atoll.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
41
42
43
44
45
46
47
48
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoll.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lalex-ku <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/05 20:24:06 by lalex-ku #+# #+# */
/* Updated: 2022/06/05 20:24:07 by lalex-ku ### ########.fr */
/* */
/* ************************************************************************** */
#include "minishell.h"
static int ft_isspace(char c);
long long ft_atoll(const char *str)
{
long long number;
int sign;
number = 0;
sign = 1;
while (ft_isspace(*str) && !(*str == '-' || *str == '+'))
{
str++;
}
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign = sign * -1;
str++;
}
while (*str && ft_isdigit(*str))
{
number = (number * 10) + (*str - '0');
str++;
}
return (number * sign);
}
static int ft_isspace(char c)
{
if (c == ' ' || c == '\f' || c == '\n')
return (1);
if (c == '\r' || c == '\t' || c == '\v')
return (1);
return (0);
}