-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_atoi.c
51 lines (47 loc) · 1.43 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
51
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sde-silv <sde-silv@student.42berlin.de> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/03/01 16:39:50 by sde-silv #+# #+# */
/* Updated: 2023/10/25 13:45:53 by sde-silv ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *nptr)
{
int i;
int n;
int sign;
i = 0;
sign = 1;
n = 0;
while (nptr[i] && ft_isspace(nptr[i]) != 0)
i ++;
if (nptr[i] == '-' || nptr[i] == '+')
{
if (nptr[i] == '-')
sign = -1;
i ++;
}
while (nptr[i] && nptr[i] >= '0' && nptr[i] <= '9')
{
n = (n * 10) + (nptr[i] - 48);
i ++;
}
return (sign * n);
}
/*
int main(void)
{
char *str;
str = "+47";
ft_putnbr_fd(atoi((const char *)str), 1);
write (1, "\n", 1);
ft_putnbr_fd(ft_atoi((const char *)str), 1);
write (1, "\n", 1);
return (0);
}
*/