-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_printfpointer.c
More file actions
42 lines (37 loc) · 1.35 KB
/
ft_printfpointer.c
File metadata and controls
42 lines (37 loc) · 1.35 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_printpoint.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: afogonca <afogonca@student.42porto.com> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/30 12:18:32 by afogonca #+# #+# */
/* Updated: 2024/10/30 12:18:52 by afogonca ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
#include <stdio.h>
static int ft_printf_adress(unsigned long p)
{
int len;
len = 0;
if (p < 16)
len += write(1, &"0123456789abcdef"[p], 1);
if (p >= 16)
{
len += ft_printf_adress(p / 16);
len += ft_printf_adress(p % 16);
}
return (len);
}
int ft_printfpointer(void *pointer)
{
int len;
len = 0;
if (!pointer)
return (ft_printfstr("(nil)"));
else
len += ft_printfstr("0x");
len += ft_printf_adress((unsigned long) pointer);
return (len);
}