forked from suhearsawho/printf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathextra_types.c
44 lines (40 loc) · 968 Bytes
/
extra_types.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
#include "holberton.h"
/**
* print_hex - prints the hex values
* @input: input address
* @base: string that represents the base characters
* Return: number of values printed
*/
int print_hex(unsigned long int input, char *base)
{
unsigned long int output;
int bytes;
bytes = 0;
if (input > 15)
bytes += print_hex(input / 16, base);
output = input % 16;
bytes += write(1, base + output, 1);
return (bytes);
}
/**
* print_address - prints the address of the input
* @input: input from variable argument list
* Return: number of characters printed
*/
int print_address(va_list input)
{
void *storage;
unsigned long int address;
char *hex_values = "0123456789abcdef";
char *start = "0x";
char *invalid = "(nil)";
storage = va_arg(input, void *);
if (storage == NULL)
{
write(1, invalid, sizeof(char) * 5);
return (5);
}
address = (unsigned long int)storage;
write(1, start, 2);
return (2 + print_hex(address, hex_values));
}