-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putnbr_fd.c
executable file
·40 lines (36 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: wdebs <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/09/24 22:29:00 by wdebs #+# #+# */
/* Updated: 2016/09/27 14:12:38 by wdebs ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_recursive(long n, int fd)
{
if (n == 0)
return ;
ft_recursive(n / 10, fd);
n = n % 10;
ft_putchar_fd(n + '0', fd);
}
void ft_putnbr_fd(int nbr, int fd)
{
long lnbr;
lnbr = nbr;
if (lnbr < 0)
{
ft_putchar_fd('-', fd);
lnbr *= -1;
}
if (lnbr == 0)
ft_putchar_fd('0', fd);
if (lnbr > 0)
{
ft_recursive(lnbr, fd);
}
}