-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr_fd.c
executable file
·38 lines (35 loc) · 1.32 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: istalevs <istalevs@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/28 16:15:04 by istalevs #+# #+# */
/* Updated: 2017/12/13 12:37:46 by istalevs ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
char x;
int tmp;
int count;
int size;
tmp = n;
count = 1;
size = 0;
while (++size && (tmp /= 10) != 0)
count *= 10;
if (n < 0)
{
write(fd, "-", 1);
while (size-- && (x = 48 - n / count) != 0 && write(fd, &x, 1))
if (n += (x - 48) * count)
count /= 10;
}
else
while (size-- && (x = 48 + n / count) != 0 && write(fd, &x, 1))
if (n -= (x - 48) * count)
count /= 10;
}