Repository navigation
Expand file tree
/
Copy pathft_pointer.c
More file actions
57 lines (50 loc) · 1.56 KB
/
Copy pathft_pointer.c
File metadata and controls
57 lines (50 loc) · 1.56 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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pointer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: mtran <mtran@student.42.fr> #+# +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2025-12-06 15:34:49 by mtran #+# #+# */
/* Updated: 2025-12-06 15:34:49 by mtran ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int ft_lowerhexalong(uintptr_t n)
{
char *str_base;
int i;
i = 0;
str_base = "0123456789abcdef";
if (n >= 16)
i += ft_lowerhexalong(n / 16);
i += ft_putchar(str_base[n % 16]);
return (i);
}
int ft_pointer(unsigned long long ptr)
{
int count;
count = 0;
if (ptr == 0)
{
write(1, "(nil)", 5);
return (5);
}
count += write(1, "0x", 2);
count += ft_lowerhexalong(ptr);
return (count);
}
// int main(void)
// {
// int x;
// int *y;
// char *str;
// x = 42;
// y = &x;
// str = "Hello";
// printf("%p \n", &y);
// x= ft_pointer(&y);
// // x = ft_pointer(str);
// // x = ft_pointer(NULL);
// return (0);
// }