-
Notifications
You must be signed in to change notification settings - Fork 1
/
ft_putnbr_fd.c
39 lines (36 loc) · 1.2 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: vbrazas <vbrazas@student.unit.ua> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 22:20:00 by vbrazas #+# #+# */
/* Updated: 2017/11/12 18:23:58 by vbrazas ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void ft_putnbr_fd(int n, int fd)
{
char buf[12];
long i;
long nn;
short j;
i = 10;
j = 2;
nn = n;
if (n < 0)
{
nn = -nn;
j++;
}
while (nn / i > 0 && ++j)
i *= 10;
j = 0;
if (n < 0)
buf[j++] = '-';
while ((i /= 10) > 0)
buf[j++] = (nn / i) % 10 + '0';
buf[j] = '\0';
ft_putstr_fd(buf, fd);
}