-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_putadd.c
44 lines (39 loc) · 1.35 KB
/
ft_putadd.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_putadd.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yanflous <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/11/25 21:48:20 by yanflous #+# #+# */
/* Updated: 2024/11/25 21:50:49 by yanflous ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int puthex(unsigned long n)
{
int count;
char *hex_based;
count = 0;
hex_based = "0123456789abcdef";
if (n <= 15)
count += ft_putchar(hex_based[n]);
else
{
count += puthex(n / 16);
count += puthex(n % 16);
}
return (count);
}
int ft_putadd(void *ptr)
{
unsigned long add;
int count;
count = 0;
if (!ptr)
return (ft_putstr("0x0"));
add = (unsigned long)ptr;
count += ft_putstr("0x");
count += puthex(add);
return (count);
}