-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_bonus.c
66 lines (59 loc) · 1.62 KB
/
utils_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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* utils_bonus.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ialdidi <ialdidi@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/21 14:44:10 by ialdidi #+# #+# */
/* Updated: 2024/01/23 09:26:33 by ialdidi ### ########.fr */
/* */
/* ************************************************************************** */
#include <unistd.h>
void ft_putchar(char c)
{
write(1, &c, 1);
}
void ft_putstr(char *s)
{
while (*s)
ft_putchar(*s++);
}
void ft_putnbr(int n)
{
long nbr;
nbr = n;
if (n < 0)
{
ft_putchar('-');
nbr = -nbr;
}
if (nbr >= 10)
{
ft_putnbr(nbr / 10);
ft_putnbr(nbr % 10);
}
else
ft_putchar(nbr + '0');
}
int ft_atoi(const char *str)
{
long num;
int sign;
num = 0;
sign = 1;
while (*str == 32 || (*str >= 9 && *str <= 13))
str++;
if (*str == '-' || *str == '+')
sign = 1 - 2 * (*str++ == '-');
while (*str >= '0' && *str <= '9')
{
if (num > 922337203685477580
|| (num == 922337203685477580 && *str - '0' > 7))
return (-1 * (sign == 1));
num = num * 10 + *str++ - '0';
}
if (!*str)
return (0);
return (num * sign);
}