-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_hexa.c
More file actions
36 lines (33 loc) · 1.39 KB
/
print_hexa.c
File metadata and controls
36 lines (33 loc) · 1.39 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* print_hexa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fschuber <fschuber@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/18 07:58:12 by fschuber #+# #+# */
/* Updated: 2023/10/19 08:33:38 by fschuber ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int print_hexa(int num, char case_format)
{
int written_chars;
unsigned int u_num;
written_chars = 0;
u_num = (unsigned int)num;
if (u_num >= 16)
{
written_chars = print_hexa(u_num / 16, case_format);
if (written_chars == -1)
return (-1);
}
if (case_format == 'x')
if (write(1, &"0123456789abcdef"[u_num % 16], 1) == -1)
return (-1);
if (case_format == 'X')
if (write(1, &"0123456789ABCDEF"[u_num % 16], 1) == -1)
return (-1);
written_chars ++;
return (written_chars);
}