-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_puthex.c
35 lines (32 loc) · 1.23 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_puthex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: gbreana <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/01/10 22:03:46 by gbreana #+# #+# */
/* Updated: 2022/01/14 02:28:39 by gbreana ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_puthex(unsigned long num, int c)
{
int cnt;
cnt = 0;
if (num >= 16)
{
cnt += ft_puthex(num / 16, c);
cnt += ft_puthex(num % 16, c);
}
else
{
if (num < 10)
cnt += ft_putnbr(num);
else if (c == 'x')
cnt += ft_putchar(num - 10 + 'a');
else if (c == 'X')
cnt += ft_putchar(num - 10 + 'A');
}
return (cnt);
}