-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putnbr_fd.c
38 lines (35 loc) · 1.25 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: scosta-j <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/14 15:28:40 by scosta-j #+# #+# */
/* Updated: 2022/12/06 19:10:22 by scosta-j ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void print_number(int number, int fd)
{
if (number > 9)
print_number(number / 10, fd);
number = (number % 10) + '0';
write(fd, &number, 1);
}
void ft_putnbr_fd(int n, int fd)
{
if (!fd && fd > 0)
return ;
if (n == -2147483648)
{
write (fd, "-2147483648", 11);
return ;
}
else if (n < 0)
{
n = n * -1;
write(fd, "-", 1);
}
print_number(n, fd);
}