-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putnbr_fd.c
48 lines (44 loc) · 1.37 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ysaito <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/06/29 20:55:46 by ysaito #+# #+# */
/* Updated: 2021/11/01 20:48:24 by ysaito ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_output_num(long ln, int fd)
{
if (ln == -2147483648)
write(fd, "-2147483648", 11);
}
void ft_putnbr_fd(int n, int fd)
{
char c[10];
long ln;
int i;
ln = n;
i = 0;
if ((ln < -2147483648 || ln > 2147483647) || ln == -2147483648)
{
ft_output_num(ln, fd);
return ;
}
else if (ln < 0)
{
write(fd, "-", 1);
ln *= -1;
}
else if (ln == 0)
write(fd, "0", 1);
while (ln)
{
c[i++] = '0' + (ln % 10);
ln = ln / 10;
}
while (i)
write(fd, &c[--i], 1);
}