-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
34 lines (31 loc) · 1.16 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: dbrandao <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/06/06 05:54:21 by dbrandao #+# #+# */
/* Updated: 2022/10/27 18:11:10 by dbrandao ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
int num;
int sign;
sign = 1;
num = 0;
while (ft_isspace(*nptr))
nptr++;
if (*nptr == '-')
sign *= -1;
if (ft_issign(*nptr))
nptr++;
while (ft_isdigit(*nptr))
{
num = num * 10 + (*nptr - 48);
nptr++;
}
return (num * sign);
}