-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
41 lines (38 loc) · 1.35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mskeleto <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/11/04 19:57:51 by mskeleto #+# #+# */
/* Updated: 2020/11/23 20:49:59 by mskeleto ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
long int resul;
int positive;
positive = 1;
resul = 0;
while (*str == ' ' || (*str >= 9 && *str <= 13))
str++;
if (*str == '+')
str++;
else if (*str == '-')
{
positive = -1;
str++;
}
while (ft_isdigit(*str))
{
resul = resul * 10 + (*str - 48);
if ((resul > 2147483648) && (positive == -1))
return (0);
if ((resul > 2147483647) && (positive == 1))
return (-1);
str++;
}
return (resul * positive);
}