-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
41 lines (38 loc) · 1.32 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: ccline <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/09/30 23:53:02 by ccline #+# #+# */
/* Updated: 2019/10/07 07:56:29 by ccline ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int res;
int neg;
int lli;
res = 0;
neg = 1;
lli = 0;
while (*str == '\n' || *str == '\t' || *str == '\v' ||
*str == '\f' || *str == '\r' || *str == ' ')
str++;
if (*str == '-' || *str == '+')
{
if (*str == '-')
neg = -1;
str++;
}
while (ft_isdigit(*str))
{
res = (res * 10) + (*str++ - '0');
lli++;
if (lli >= 19)
return ((neg == -1) ? 0 : (-1));
}
return (res * neg);
}