-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_atoi.c
48 lines (44 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_atoi.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: polmarti <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/07/19 11:18:52 by polmarti #+# #+# */
/* Updated: 2023/07/24 20:21:23 by polmarti ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
int ft_atoi(const char *str)
{
int output;
int sign;
output = 0;
sign = 1;
while (*str && (ft_strchr("\n\t\v\f\r ", *str)) != NULL)
str++;
if (*str == '+')
str++;
else if (*str == '-')
{
str++;
sign = -1;
}
while (*str && (ft_strchr("0123456789", *str)) != NULL)
{
output = (output * 10) + (*str - '0');
str++;
}
return (output * sign);
}
/*#include <unistd.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
if (argc == 1)
write(1, "\n", 1);
int result = ft_atoi(argv[1]);
printf("%d\n", result);
return (0);
}*/