-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft2_putfd.c
49 lines (44 loc) · 1.34 KB
/
ft2_putfd.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putfd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lpalacio <lpalacio@student.42madrid.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/30 17:28:26 by lpalacio #+# #+# */
/* Updated: 2022/09/30 17:30:41 by lpalacio ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_putint_fd(int n, int fd)
{
char c;
if (n < 0)
{
ft_putchar_fd ('-', fd);
n = -n;
}
c = '0' + n;
ft_putchar_fd(c, fd);
}
void ft_putnbr_fd(int n, int fd)
{
int num;
num = 0;
if (n < 10 && n > -10)
ft_putint_fd(n, fd);
else if (n <= -10)
{
num = -(n % 10);
n = n / 10;
ft_putnbr_fd(n, fd);
ft_putint_fd(num, fd);
}
else if (n >= 10)
{
num = n % 10;
n = n / 10;
ft_putnbr_fd(n, fd);
ft_putint_fd(num, fd);
}
}