-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
41 lines (38 loc) · 1.41 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: abkssiba <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/17 10:48:19 by abkssiba #+# #+# */
/* Updated: 2021/05/24 16:03:43 by abkssiba ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int iss;
long value;
long number;
int sign;
iss = 0;
number = 0;
sign = 1;
while ((str[iss] == ' ' || (str[iss] >= '\t' && str[iss] <= '\r'))
&& str[iss] != '\0')
iss++;
if (str[iss] == '-' || str[iss] == '+')
if (str[iss++] == '-')
sign = -1;
while (ft_isdigit(str[iss]))
{
value = number;
number = (number * 10) + (sign * (str[iss++] - '0'));
if (sign == 1 && value > number)
return (-1);
else if (sign == -1 && value < number)
return (0);
}
return (number);
}