-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr_fd.c
47 lines (42 loc) · 1.33 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: msubtil- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/19 23:54:45 by msubtil- #+# #+# */
/* Updated: 2022/05/11 22:27:41 by msubtil- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static int ft_base_ten_nbr(long n)
{
int base;
base = 1;
while (n >= 10)
{
n /= 10;
base *= 10;
}
return (base);
}
void ft_putnbr_fd(int n, int fd)
{
long aux_nb;
int nbr_base;
char chr_to_write;
aux_nb = (long) n;
if (n < 0)
{
aux_nb *= -1;
write(fd, "-1", 1);
}
nbr_base = ft_base_ten_nbr(aux_nb);
while (nbr_base)
{
chr_to_write = (aux_nb / nbr_base) % 10 + '0';
write(fd, &chr_to_write, 1);
nbr_base /= 10;
}
}