-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_printf_ptr.c
50 lines (44 loc) · 1.37 KB
/
ft_printf_ptr.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
47
48
49
50
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printf_ptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: danalmei <danalmei@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/29 21:27:55 by danalmei #+# #+# */
/* Updated: 2023/05/03 18:19:17 by danalmei ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_write_ptr(unsigned long ptr)
{
int index;
int c;
c = 0;
index = 0;
if (ptr >= 16)
{
c += ft_write_ptr(ptr / 16);
c += ft_write_ptr(ptr % 16);
}
else
{
index = ptr % 16;
ft_putchar_fdp(HEX_L[index], 1);
c++;
}
return (c);
}
int ft_print_ptr(unsigned long ptr)
{
int print_len;
print_len = 0;
if (ptr == 0)
return (ft_putstr_fdp("(nil)", 1));
else
{
print_len += ft_putstr_fdp("0x", 1);
print_len += ft_write_ptr(ptr);
}
return (print_len);
}