-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_putnbrfunctions.c
81 lines (72 loc) · 1.92 KB
/
ft_putnbrfunctions.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putnbrfunctions.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jmatheis <[email protected]. +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/04/25 16:25:35 by jmatheis #+# #+# */
/* Updated: 2023/08/21 17:22:27 by jmatheis ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_putchar_nbr(char c, int *counter)
{
write (1, &c, 1);
(*counter)++;
}
void ft_putnbr(int n, int *counter)
{
if (n < 0)
{
ft_putchar_nbr('-', counter);
if (n == -2147483648)
{
write(1, "2147483648", 10);
*counter += 10;
return ;
}
n = -n;
}
if (n > 9)
{
ft_putnbr(n / 10, counter);
n = n % 10;
}
ft_putchar_nbr(n + 48, counter);
}
void ft_u_putnbr(int n, int *counter)
{
unsigned int i;
i = 4294967296 + n;
if (i > 9)
{
ft_putnbr(i / 10, counter);
i = i % 10;
}
ft_putchar_nbr(i + 48, counter);
}
void ft_p_x_putnbr(unsigned long int ch, int *counter)
{
char *base16;
base16 = "0123456789abcdef";
if (ch > 15)
{
ft_p_x_putnbr(ch / 16, counter);
ft_p_x_putnbr(ch % 16, counter);
}
if (ch < 16)
ft_putchar_nbr(base16[ch], counter);
}
void ft_bigx_putnbr(unsigned int ch, int *counter)
{
char *base16;
base16 = "0123456789ABCDEF";
if (ch > 15)
{
ft_bigx_putnbr(ch / 16, counter);
ft_bigx_putnbr(ch % 16, counter);
}
if (ch < 16)
ft_putchar_nbr(base16[ch], counter);
}