-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
48 lines (44 loc) · 1.37 KB
/
ft_atoi.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jeshin <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/06 13:12:36 by jeshin #+# #+# */
/* Updated: 2024/06/05 17:00:17 by jeshin ### ########.fr */
/* */
/* ************************************************************************** */
static int is_space(const char ch)
{
if (ch == 32 || (ch >= 9 && ch <= 13))
return (1);
return (0);
}
static int is_digit(const char ch)
{
if (ch >= '0' && ch <= '9')
return (1);
return (0);
}
int ft_atoi(const char *str)
{
long long sign;
long long ret;
ret = 0;
sign = 1;
while (is_space(*str))
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
sign = -1;
str++;
}
while (is_digit(*str))
{
ret = ret * 10 + (*str - '0');
str++;
}
return ((int)(sign * ret));
}