-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_utils.c
46 lines (42 loc) · 1.45 KB
/
ft_printf_utils.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
42
43
44
45
46
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_itoa.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aperis-p <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/05/10 15:58:48 by aperis-p #+# #+# */
/* Updated: 2023/06/27 15:54:20 by aperis-p ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_itoa(unsigned long n, int base, int caps)
{
int count;
char *hexa_chrs;
count = 0;
if (caps)
hexa_chrs = "0123456789ABCDEF";
else
hexa_chrs = "0123456789abcdef";
if (n < (unsigned long)base)
return (ft_putchar(hexa_chrs[n]));
else
{
count = ft_itoa(n / base, base, caps);
return (count + ft_itoa(n % base, base, caps));
}
}
int hash_printer(unsigned long n, int base)
{
if (!n)
{
write(1, "(nil)", 5);
return (5);
}
if (base == 16)
ft_putstr("0x");
else if (base == 8)
ft_putstr("0");
return (ft_itoa(n, base, 0) + 2);
}