-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
34 lines (32 loc) · 1.2 KB
/
Copy pathft_atoi.c
File metadata and controls
34 lines (32 loc) · 1.2 KB
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: tsargsya <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/12/09 15:52:29 by tsargsya #+# #+# */
/* Updated: 2024/12/11 18:40:00 by tsargsya ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *nptr)
{
int res;
int sign;
res = 0;
sign = 1;
while ((*nptr >= 9 && *nptr <= 13) || *nptr == ' ')
nptr++;
if (*nptr == '-' || *nptr == '+')
{
if (*nptr == '-')
sign *= -1;
nptr++;
}
while (*nptr >= '0' && *nptr <= '9')
{
res = (res * 10) + (*nptr - 48);
nptr++;
}
return (res * sign);
}