-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_puthex.c
More file actions
37 lines (34 loc) · 1.29 KB
/
Copy pathft_puthex.c
File metadata and controls
37 lines (34 loc) · 1.29 KB
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: mbarranq <mbarranq@student.42malaga.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/04 12:32:49 by mbarranq #+# #+# */
/* Updated: 2024/10/04 13:31:39 by mbarranq ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_puthex(unsigned int num, char format)
{
int count;
char *hex_digits;
count = 0;
if (format == 'x')
hex_digits = "0123456789abcdef";
else if (format == 'X')
hex_digits = "0123456789ABCDEF";
else
return (-1);
if (num >= 16)
{
count += ft_puthex(num / 16, format);
count += ft_puthex(num % 16, format);
}
else
{
count += ft_putchar(hex_digits[num]);
}
return (count);
}