-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_puthex.c
37 lines (34 loc) · 1.3 KB
/
ft_puthex.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_puthex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tjkruger <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/03 05:36:31 by tjkruger #+# #+# */
/* Updated: 2024/11/11 13:22:43 by tjkruger ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_puthex(unsigned long format, int uppercase, int *chars_pr)
{
char *digits;
char hexdigits[16];
int i;
i = 0;
if (uppercase == 1)
digits = "0123456789ABCDEF";
else
digits = "0123456789abcdef";
if (format == 0)
ft_putchar('0', chars_pr);
while (format)
{
hexdigits[i] = digits[format % 16];
format /= 16;
i++;
}
while (i-- > 0)
ft_putchar(hexdigits[i], chars_pr);
return (*chars_pr);
}