-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointer.c
More file actions
45 lines (43 loc) · 720 Bytes
/
pointer.c
File metadata and controls
45 lines (43 loc) · 720 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
#include "main.h"
/**
* po - Function that gives the address in hexdecimal and start
* by 0x
* @arg: Variadic Arguments from user [Int]
* Return: length of digits
*/
int po(va_list arg)
{
unsigned long int n = va_arg(arg, unsigned long int), len, i, m, temp;
char *s;
len = 0;
if (n == 0)
{
write(1, "(nil)", 5);
return (5);
}
write(1, "0x", 2);
i = 0;
m = n;
temp = n;
while (m)
{
len++;
m /= 16;
}
s = malloc(len + 1);
if (s == NULL)
return (0);
for (i = len - 1; temp != 0; i--)
{
if ((temp % 16) < 10)
s[i] = (temp % 16) + '0';
else
s[i] = (temp % 16) + 'W';
temp /= 16;
}
s[len] = '\0';
for (i = 0; i < len; i++)
write(1, &s[i], 1);
free(s);
return (len + 2);
}