-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
49 lines (46 loc) · 1.42 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
49
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: vstockma <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/13 11:06:06 by vstockma #+# #+# */
/* Updated: 2022/09/13 11:06:27 by vstockma ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *str)
{
int i;
int a;
long value;
value = 0;
i = 0;
a = 1;
while (str[i] && ((str[i] >= 7 && str[i] <= 13) || str[i] == ' '))
i++;
if (str[i] == '-' || str[i] == '+')
{
if (str[i] == '-')
a = -a;
i++;
}
while (str[i] && str[i] >= '0' && str[i] <= '9')
{
value = 10 * value + (str[i] - 48);
i++;
if (value * a < -2147483648)
return (0);
else if (value * a > 2147483647)
return (-1);
}
return ((int)value * a);
}
/*
int main()
{
char str[] = "\x079";
printf("%d", ft_atoi(str));
return (0);
}
*/