-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putnbr_fd.c
33 lines (29 loc) · 1.16 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yxu <yxu@student.42tokyo.jp> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/24 13:03:57 by yxu #+# #+# */
/* Updated: 2023/09/24 18:35:48 by yxu ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void write_num(long int num, int fd)
{
if (num >= 10)
write_num(num / 10, fd);
write(fd, &"0123456789"[num % 10], 1);
}
void ft_putnbr_fd(int n, int fd)
{
long int num;
num = n;
if (num < 0)
{
write(fd, "-", 1);
num = -num;
}
write_num(num, fd);
}