-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_atoi.c
More file actions
43 lines (39 loc) · 1.3 KB
/
ft_atoi.c
File metadata and controls
43 lines (39 loc) · 1.3 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
35
36
37
38
39
40
41
42
43
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lbiasuz <lbiasuz@student.42sp.org.br> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/10 22:15:38 by lbiasuz #+# #+# */
/* Updated: 2022/04/16 15:05:53 by lbiasuz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_isspace(char c)
{
if (c == '\f' || c == '\n'
|| c == '\r' || c == '\t'
|| c == '\v' || c == ' ')
return (1);
return (0);
}
int ft_atoi(const char *nptr)
{
int i;
int n;
i = 0;
n = 1;
while (ft_isspace(*nptr))
nptr++;
if (*nptr == '-')
n = -1;
if (*nptr == '-' || *nptr == '+')
nptr++;
while (ft_isdigit(*nptr))
{
i = (i * 10) + (*nptr - 48);
nptr++;
}
return (i * n);
}