-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr_fd.c
50 lines (43 loc) · 1.31 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
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: emdi-mar <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/08 22:01:22 by emdi-mar #+# #+# */
/* Updated: 2024/11/08 22:02:02 by emdi-mar ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void put(int c, int fd)
{
char r;
r = c + 48;
ft_putchar_fd(r, fd);
}
static void divide(long int numbr, int fd)
{
long int num;
num = numbr;
if (numbr / 10)
{
num = numbr % 10;
numbr = numbr / 10;
divide(numbr, fd);
put(num, fd);
}
else
put(num, fd);
}
void ft_putnbr_fd(int n, int fd)
{
long int lnb;
lnb = n;
if (lnb < 0)
{
lnb = lnb * -1;
ft_putchar_fd(45, fd);
}
divide(lnb, fd);
}