-
Notifications
You must be signed in to change notification settings - Fork 0
/
putptr.c
58 lines (51 loc) · 1.42 KB
/
putptr.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
51
52
53
54
55
56
57
58
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* putptr.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: malema <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/01/12 19:01:10 by malema #+# #+# */
/* Updated: 2023/01/17 14:48:16 by malema ### ########.fr */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
int ft_counter2(unsigned long long nb)
{
int count ;
count = 0;
while (nb != 0)
{
count++;
nb = nb / 16;
}
return (count);
}
void ft_writehex2(unsigned long long hex)
{
char *arr;
arr = "0123456789abcdef";
if (hex >= 16)
{
ft_writehex2(hex / 16);
ft_writehex2(hex % 16);
}
else
{
ft_printchar(arr[hex % 16]);
}
}
int ft_printptr(unsigned long long ptr)
{
int c;
c = 0;
c = c + write(1, "0x", 2);
if (ptr == 0)
c = c + ft_printchar(48);
else
{
ft_writehex2(ptr);
}
c += ft_counter2(ptr);
return (c);
}