-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
26 lines (24 loc) · 1.17 KB
/
ft_atoi.c
File metadata and controls
26 lines (24 loc) · 1.17 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: cde-la-r <cde-la-r@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/08/10 19:01:20 by cde-la-r #+# #+# */
/* Updated: 2023/09/20 13:13:55 by cde-la-r ### ########.fr */
/* */
/* ************************************************************************** */
int ft_atoi(const char *nptr)
{
unsigned int n;
int sgn;
while (*nptr == ' ' || (*nptr >= '\t' && *nptr <= '\r'))
nptr++;
sgn = (*nptr != '-') - (*nptr == '-');
nptr += (*nptr == '-' || *nptr == '+');
n = 0;
while (*nptr >= '0' && *nptr <= '9')
n = n * 10 + (*nptr++ - '0');
return (sgn * n);
}