-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathp.c
More file actions
58 lines (56 loc) · 992 Bytes
/
p.c
File metadata and controls
58 lines (56 loc) · 992 Bytes
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
#include "holberton.h"
/**
*print_px - prints address in hex
*@count: keeps count
*@ptr_val: address
*Return: count
*/
int print_px(int count, unsigned long int ptr_val)
{
unsigned long int temp_num = ptr_val;
unsigned long int num;
int i = 0, len = 0;
char hexnum[50];
while (temp_num != 0)
{
num = temp_num % 16;
if (num < 10)
num += 48;
else
num += 87;
hexnum[i] = num;
i++;
temp_num /= 16;
}
hexnum[i] = '\0';
while (hexnum[len] != '\0')
len++;
_putchar('0');
_putchar('x');
count += 2;
for (i = len - 1; i >= 0; i--)
{
_putchar(hexnum[i]);
count++;
}
return (count);
}
/**
*print_p - prints address of ptr in hex
*@count: keeps count
*@list: list
*Return: count
*/
int print_p(int count, va_list list)
{
void *temp = va_arg(list, void *);
unsigned long int ptr_val;
if (temp == NULL)
{
count += _printf("(nil)");
return (count);
}
ptr_val = *(unsigned long int *) &temp;
count = print_px(count, ptr_val);
return (count);
}