-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr_fd.c
52 lines (48 loc) · 1.38 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
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/20 15:47:49 by ohachim #+# #+# */
/* Updated: 2018/10/20 15:47:52 by ohachim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void ft_putnegative_fd(int n, int fd)
{
if (n == -2147483648)
{
ft_putstr_fd("-2147483648", fd);
}
else
{
ft_putchar_fd('-', fd);
n = n * -1;
ft_putnbr_fd(n, fd);
}
}
void ft_putnbr_fd(int n, int fd)
{
long int dec;
long int fn;
if (n < 0)
ft_putnegative_fd(n, fd);
else
{
fn = n;
dec = 1;
while (fn / 10 != 0)
{
dec = dec * 10;
fn = fn / 10;
}
while (dec > 0)
{
ft_putchar_fd((n / dec) + '0', fd);
n = n % dec;
dec = dec / 10;
}
}
}