-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
35 lines (33 loc) · 1.19 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rvandepu <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/18 21:16:27 by rvandepu #+# #+# */
/* Updated: 2023/10/18 21:38:06 by rvandepu ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *nptr)
{
int s;
long n;
while (*nptr == ' ' || ('\t' <= *nptr && *nptr <= '\r'))
nptr++;
s = 1;
if (*nptr == '-' || *nptr == '+')
{
if (*nptr == '-')
s = -s;
nptr++;
}
n = 0;
while ('0' <= *nptr && *nptr <= '9')
{
n *= 10;
n += *nptr - '0';
nptr++;
}
return ((int)(s * n));
}