-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
36 lines (33 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_atoi.c :+: :+: */
/* +:+ */
/* By: splattje <splattje@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2023/10/04 16:10:30 by splattje #+# #+# */
/* Updated: 2023/10/18 16:58:33 by splattje ######## odam.nl */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
int integer;
int sign;
integer = 0;
sign = 1;
while ((*nptr >= 9 && *nptr <= 13) || *nptr == 32)
nptr++;
if (*nptr == '+' || *nptr == '-')
{
if (*nptr == '-')
sign = -1;
nptr++;
}
while (ft_isdigit(*nptr))
{
integer = integer * 10 + (*nptr - '0');
nptr++;
}
return (integer * sign);
}