-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_ptr.c
65 lines (58 loc) · 1.54 KB
/
print_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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/* ************************************************************************** */
/* */
/* :::::::: */
/* print_ptr.c :+: :+: */
/* +:+ */
/* By: dreijans <[email protected]> +#+ */
/* +#+ */
/* Created: 2022/11/25 13:33:51 by dreijans #+# #+# */
/* Updated: 2022/12/05 13:58:26 by dreijans ######## odam.nl */
/* */
/* ************************************************************************** */
#include "ft_printf.h"
static int how_much(unsigned long int a)
{
int i;
i = 0;
if (a == 0)
i++;
while (a != 0)
{
a = a / 16;
i++;
}
return (i);
}
static int put_pointer(unsigned long int n)
{
int nbr;
if ((n / 16) != 0)
put_pointer(n / 16);
if ((n % 16) < 10)
{
nbr = print_char((n % 16) + '0');
if (nbr == -1)
return (-1);
}
else
{
nbr = print_char((n % 16) + 'a');
if (nbr == -1)
return (-1);
}
return (nbr);
}
int print_ptr(unsigned long int n)
{
int count;
int nbr;
int tmp;
tmp = print_str("0x");
if (tmp == -1)
return (-1);
count = how_much(n);
nbr = put_pointer(n);
if (nbr == -1)
return (-1);
return (count + tmp);
}