-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
45 lines (41 loc) · 1.43 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: taehkwon <taehkwon@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/21 16:33:31 by taehkwon #+# #+# */
/* Updated: 2023/07/20 18:56:08 by taehkwon ### ########.fr */
/* */
/* ************************************************************************** */
#include "fdf.h"
static int ft_isspace(char c)
{
if (c == ' ' || (c >= 9 && c <= 13))
return (1);
else
return (0);
}
int ft_atoi(const char *str)
{
long long result;
int sign;
result = 0;
while (ft_isspace(*str))
str++;
sign = 1;
if (*str == '-')
sign = -1;
if (*str == '+' || *str == '-')
str++;
while (*str && (*str >= '0' && *str <= '9'))
{
result = result * 10 + (*str - '0');
str++;
if (result > 2147483647 || result * sign < -2147483648)
ft_perror("ERROR: map->z range error");
}
result = result * sign;
return ((int)result);
}