-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
50 lines (46 loc) · 1.37 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: tiagalex <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/12 14:12:45 by tiagalex #+# #+# */
/* Updated: 2024/11/12 14:12:49 by tiagalex ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//Converte uma str em um int.
int ft_atoi(const char *str)
{
int i;
int r;
int signal;
char *s;
signal = 1;
r = 0;
i = 0;
s = (char *)str;
while (s[i] == ' ' || (s[i] >= 9 && s[i] <= 13))
{
i++;
}
if (s[i] == '-' || s[i] == '+')
{
if (s[i] == '-')
signal = (-1);
i++;
}
while (s[i] >= '0' && s[i] <= '9')
{
r = r * 10 + (s[i] - '0');
i++;
}
return (r * signal);
}
/*
int main(int argc, char **argv)
{
(void)argc;
printf("%d\n", ft_atoi(argv[1]));
} */