-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_puthex.c
32 lines (29 loc) · 1.24 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_puthex.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ftonita <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/11/15 21:51:07 by ftonita #+# #+# */
/* Updated: 2021/11/15 21:51:08 by ftonita ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
size_t ft_puthex(unsigned int n, int type)
{
int c;
c = 0;
if (n >= 16)
c += ft_puthex(n / 16, type);
if (n % 16 < 16 && n % 16 > 9)
{
if (type == 0)
c += ft_putchar('a' + (n % 16) - 10);
else if (type == 1)
c += ft_putchar('A' + (n % 16) - 10);
}
else if (n % 16 < 10 && n % 16 >= 0)
c += ft_putchar(n % 16 + '0');
return (c);
}