-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
30 lines (27 loc) · 1.21 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jovicto2 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/18 10:14:11 by jovicto2 #+# #+# */
/* Updated: 2023/05/18 10:14:42 by jovicto2 ### ########.fr */
/* */
/* ************************************************************************** */
#include "../includes/libft.h"
int ft_atoi(const char *nptr)
{
int number;
int sign;
number = 0;
sign = 1;
while ((*nptr >= '\t' && *nptr <= '\r') || *nptr == ' ')
nptr++;
if (*nptr == '-' || *nptr == '+')
if (*nptr++ == '-')
sign = -1;
while (ft_isdigit(*nptr))
number = (number * 10) + (*nptr++ - '0');
return (number * sign);
}