-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_addr.c
66 lines (58 loc) · 1016 Bytes
/
print_addr.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
66
#include "main.h"
/**
* print_hex - Prints hexadecimal representation of
* an long int
* @num: num we want to covert
* @pCount: Pointer to counter
* Return:0
*/
int print_hex(unsigned long int num, int *pCount)
{
char buffer[32];
int i;
i = 0;
if (num == 0)
{
_putchar('0');
(*pCount)++;
return (1);
}
while (num > 0)
{
buffer[i] = (num % 16) + (num % 16 > 9 ? 'a' - 10 : '0');
num /= 16;
i++;
}
i--;
while (i >= 0)
{
_putchar(buffer[i]);
i--;
(*pCount)++;
}
return (0);
}
/**
* print_addr - fun that print the addresse
* @pa: Points to the list of arguments
* @pCount: Pointer to counter
* Return: i if point to nothing, 0 otherwise
*/
int print_addr(va_list pa, int *pCount)
{
void *addr = va_arg(pa, void *);
char *str = "(nil)";
long int num;
if (addr == NULL)
{
_putstr(str, _strlen(str));
*pCount += _strlen(str);
return (1);
}
_putchar('0');
_putchar('x');
*pCount += 2;
num = (unsigned long int)addr;
print_hex(num, pCount);
return (0);
}