-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
50 lines (44 loc) · 1.38 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
38
39
40
41
42
43
44
45
46
47
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpouget <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/14 16:59:35 by tpouget #+# #+# */
/* Updated: 2020/12/02 00:20:22 by tpouget ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
long result;
size_t i;
size_t neg;
result = 0;
i = 0;
neg = 0;
while (ft_isspace(nptr[i]))
i++;
if (nptr[i] == '+')
i++;
else if (nptr[i] == '-')
neg = ++i;
while (ft_isdigit(nptr[i]))
{
result *= 10;
result += nptr[i] - '0';
i++;
}
return (neg ? -result : result);
}
/*
#include <stdio.h>
int main(int argc, char **argv)
{
if (argc !=2) return 0;
printf("%d\n", atoi(argv[1]));
printf("%d\n", ft_atoi(argv[1]));
return 0;
}
*/