-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions_utils1_bonus.c
95 lines (86 loc) · 2.12 KB
/
functions_utils1_bonus.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* functions_utils1_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ansebast <ansebast@student.42luanda.com +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/21 22:54:33 by ansebast #+# #+# */
/* Updated: 2024/11/21 23:19:00 by ansebast ### ########.fr */
/* */
/* ************************************************************************** */
#include "minitalk_bonus.h"
long ft_atol(const char *str)
{
int i;
int signal;
long num;
signal = 1;
num = 0;
i = 0;
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
i++;
if (str[i] == '-')
signal = -1;
if (str[i] == '-' || str[i] == '+')
i++;
while (ft_isdigit(str[i]))
{
num = num * 10 + str[i] - '0';
i++;
}
return (num * signal);
}
long int ft_strtol(char *str, char **endptr)
{
int i;
int signal;
long num;
signal = 1;
num = 0;
i = 0;
while (str[i] == 32 || (str[i] >= 9 && str[i] <= 13))
i++;
if (str[i] == '-')
signal = -1;
if (str[i] == '-' || str[i] == '+')
i++;
while (ft_isdigit(str[i]))
{
num = num * 10 + str[i] - '0';
i++;
}
*endptr = &str[i];
return (num * signal);
}
void ft_putnbr_fd(long n, int fd)
{
if (n == -2147483648)
{
write(fd, "-2147483648", 11);
return ;
}
if (n < 0)
{
ft_putchar_fd('-', fd);
n = -n;
}
if (n > 9)
ft_putnbr_fd(n / 10, fd);
ft_putchar_fd((n % 10 + '0'), fd);
}
int ft_isint(char *str)
{
char *endptr;
if (*str == '\0' || (*str == '-' && *(str + 1) == '\0') || (*str == '+'
&& *(str + 1) == '\0'))
return (0);
ft_strtol(str, &endptr);
if (*endptr != '\0')
return (0);
return (1);
}
int ft_isdigit(int ch)
{
return (ch >= '0' && ch <= '9');
}