-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_pointer.c
More file actions
80 lines (66 loc) · 1.76 KB
/
Copy pathft_pointer.c
File metadata and controls
80 lines (66 loc) · 1.76 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_pointer.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: atok <atok@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/11/04 13:31:30 by atok #+# #+# */
/* Updated: 2022/11/10 11:04:55 by atok ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
void ft_printptr(unsigned long p)
{
if (p >= 16)
ft_printptr(p / 16);
write(1, &"0123456789abcdef"[p % 16], 1);
}
int ft_ptrlen(unsigned long p)
{
int i;
i = 0;
while (p != 0)
{
p = p / 16;
i++;
}
return (i);
}
int ft_pointer(unsigned long p)
{
int print_len;
print_len = 0;
if (p == 0)
print_len += write (1, "0x0", 3);
else if (p > 0)
{
print_len += write (1, "0x", 2);
ft_printptr(p);
print_len += ft_ptrlen(p);
}
return (print_len);
}
/* #include <stdio.h>
int main()
{
void *a;
printf("Size - void pointer:%lu",sizeof(a));
return 0;
}
on a 16 bit machine pointer == 2 byte
32 == 4 byte
64 == 8 byte */
/* #include <stdio.h>
void ft_putptr(unsigned long num)
{
if (num >= 16)
ft_putptr(num / 16);
printf("%c" ,"0123456789abcdef"[num % 16]);
}
int main()
{
ft_putptr(2736456);
return 0;
}
conver int to hex */