-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr_fd.c
39 lines (35 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: radan <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/22 16:46:43 by radan #+# #+# */
/* Updated: 2021/10/22 16:46:45 by radan ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static unsigned int ft_module(int n)
{
if (n < 0)
return (n * (-1));
else
return (n);
}
void ft_putnbr_fd(int n, int fd)
{
unsigned int num;
if (fd < 0)
return ;
if (n < 0)
ft_putchar_fd ('-', fd);
num = ft_module(n);
if (num >= 10)
{
ft_putnbr_fd(num / 10, fd);
ft_putnbr_fd(num % 10, fd);
}
else
ft_putchar_fd(num + '0', fd);
}