-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
37 lines (34 loc) · 1.25 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
37
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gantonio <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/05/19 17:59:01 by gantonio #+# #+# */
/* Updated: 2021/05/19 20:04:34 by gantonio ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
int j;
int n;
j = 1;
n = 0;
while (*nptr == ' ' || *nptr == '\t' || *nptr == '\n'
|| *nptr == '\v' || *nptr == '\f' || *nptr == '\r')
nptr++;
if (*nptr == '-' || *nptr == '+')
{
if (*nptr == '-')
j *= -1;
nptr++;
}
while (*nptr > 47 && *nptr < 58)
{
n = (*nptr - '0') + (n * 10);
nptr++;
}
return (n * j);
}