-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
37 lines (33 loc) · 1.31 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mavinici <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/18 20:02:00 by mavinici #+# #+# */
/* Updated: 2021/05/18 20:02:00 by mavinici ### ########.fr */
/* */
/* ************************************************************************** */
#include <libft.h>
static int ft_ignore(char c)
{
if ((c >= 9 && c <= 13) || c == ' ')
return (1);
return (0);
}
int ft_atoi(const char *nptr)
{
int sign;
int number;
sign = 1;
number = 0;
while (ft_ignore(*nptr) == 1)
nptr++;
if (*nptr == '-' || *nptr == '+')
if (*nptr++ == '-')
sign *= -1;
while (ft_isdigit(*nptr) == 1)
number = number * 10 + (*nptr++ - '0');
return (number * sign);
}