-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_xx.c
52 lines (47 loc) · 1.42 KB
/
ft_printf_xx.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_printf_xx.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mcoskune <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/29 15:59:09 by mcoskune #+# #+# */
/* Updated: 2024/05/01 11:06:51 by mcoskune ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static size_t ft_len(unsigned int n)
{
size_t len;
len = 0;
if (n <= 0)
len++;
while (n)
{
n /= 16;
len++;
}
return (len);
}
int ft_printf_xx(unsigned int n, int x_case)
{
char *hex_base;
size_t len;
len = ft_len(n);
hex_base = "0123456789abcdef";
if (x_case == 1)
hex_base = "0123456789ABCDEF";
if (n < 16)
{
if (ft_printf_c(hex_base[n]) == -1)
return (-1);
}
else
{
if (ft_printf_xx(n / 16, x_case) == -1)
return (-1);
if (ft_printf_xx(n % 16, x_case) == -1)
return (-1);
}
return (len);
}