-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_x.c
52 lines (48 loc) · 1.86 KB
/
ft_printf_x.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_x.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: estettle <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/25 14:16:14 by estettle #+# #+# */
/* Updated: 2024/10/25 15:09:58 by estettle ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
/**
* @brief Puts an unsigned integer to the standard input in the specified base.
*
* @param nb The number to print.
* @param charset The charset for the base (length determines the base number).
*/
static void ft_putnbr_base(unsigned int nb, char *charset, int *count)
{
unsigned short base;
base = ft_strlen(charset);
if (nb >= base)
{
ft_putnbr_base(nb / base, charset, count);
nb = nb % base;
}
if (nb < base)
{
(*count)++;
ft_putchar_fd(charset[nb], 1);
}
}
/**
* @brief Prints an unsigned hexadecimal number to stdout, counting the number
* of bytes written.
*
* @param nb The unsigned integer to process.
* @param count A pointer to the number of bytes written by ft_printf() so far.
* @param is_uppercase 1 if using uppercase letters, 0 if lowercase.
*/
void process_hex(unsigned int nb, int *count, int is_uppercase)
{
if (is_uppercase)
ft_putnbr_base(nb, "0123456789ABCDEF", count);
else
ft_putnbr_base(nb, "0123456789abcdef", count);
}