-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbr_fd.c
58 lines (53 loc) · 1.56 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
53
54
55
56
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbr_fd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sgrindhe <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/07/17 09:29:24 by sgrindhe #+# #+# */
/* Updated: 2018/08/05 00:30:59 by sgrindhe ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
static void make_sized_array(int size, int nb, int fd)
{
int digit_array[size];
int hold_size;
hold_size = size;
while (size > 0)
{
digit_array[size - 1] = nb % 10;
nb = nb / 10;
size--;
}
while (size < hold_size)
{
ft_putchar_fd(digit_array[size] + 48, fd);
size++;
}
}
void ft_putnbr_fd(int nb, int fd)
{
int digit_counter;
int num_holder;
if (nb < 0)
{
ft_putchar_fd('-', fd);
nb = nb * -1;
}
if (nb == -2147483648)
{
ft_putnbr_fd(2, fd);
ft_putnbr_fd(147483648, fd);
return ;
}
num_holder = nb;
digit_counter = 1;
while (num_holder >= 10)
{
num_holder = num_holder / 10;
digit_counter++;
}
make_sized_array(digit_counter, nb, fd);
}