-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putnbr_fd.c
47 lines (43 loc) · 1.32 KB
/
ft_putnbr_fd.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: eablak <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/16 10:10:22 by eablak #+# #+# */
/* Updated: 2022/10/16 10:10:23 by eablak ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_putchar(char c, int fd)
{
write(fd, &c, 1);
}
static void ft_putnbr(int nbr, int f)
{
if (nbr == -2147483648)
{
ft_putchar('-', f);
nbr = nbr / 10;
ft_putnbr(-nbr, f);
ft_putchar('8', f);
}
else if (nbr < 0)
{
ft_putchar('-', f);
ft_putnbr(-nbr, f);
}
else
{
if (nbr > 9)
{
ft_putnbr(nbr / 10, f);
}
ft_putchar('0' + (nbr % 10), f);
}
}
void ft_putnbr_fd(int n, int fd)
{
ft_putnbr(n, fd);
}