-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_puthex.c
41 lines (36 loc) · 1.26 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
38
39
40
41
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_puthex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mchaibi <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/14 16:41:44 by mchaibi #+# #+# */
/* Updated: 2024/12/05 11:46:41 by mchaibi ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
char ft_getchr(int n, char x)
{
char *str;
str = NULL;
if (x == 'x')
str = "0123456789abcdef";
else if (x == 'X')
str = "0123456789ABCDEF";
return (str[n]);
}
int ft_puthex(unsigned int n, char x)
{
char c;
int count;
count = 0;
if (n >= 16)
{
count += ft_puthex(n / 16, x);
}
c = ft_getchr(n % 16, x);
write(1, &c, 1);
count++;
return (count);
}