-
Notifications
You must be signed in to change notification settings - Fork 0
/
more_more_conversion_functions.c
79 lines (67 loc) · 1.27 KB
/
more_more_conversion_functions.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
67
68
69
70
71
72
73
74
75
76
77
78
79
#include <unistd.h>
#include <stdarg.h>
#include "main.h"
/**
* stringLength - get string lenght
* @str: va_list object
* Return: (lenght)
*/
int stringLength(const char *str)
{
int length = 0;
while (str[length] != '\0')
length++; /* end while */
return (length);
} /* end function */
/**
* writeString - printing the string
* @str: va_list object
*
*/
void writeString(const char *str)
{
int length = stringLength(str);
write(1, str, length);
} /* end function */
/**
* writeChar - print character
* @c: va_list object
*/
void writeChar(char c)
{
write(1, &c, 1);
} /* end function */
/**
* writeHex - print hexadecimal
* @value: parameters
*/
void writeHex(unsigned long value)
{
const char hexDigits[] = "0123456789ABCDEF";
char buffer[16];
int index = 0;
if (value == 0)
{
writeChar('0');
return;
} /* end if */
while (value > 0 && index < 16)
{
int digit = value % 16;
buffer[index++] = hexDigits[digit];
value /= 16;
} /* end while */
while (index > 0)
writeChar(buffer[--index]);
/* end while */
} /* end function */
/**
* handle_memory_address - handles the 'p' specifier
* @ptr: pointer
*/
void handle_memory_address(void *ptr)
{
unsigned long address = (unsigned long)ptr;
writeString("0x");
writeHex(address);
} /* end function */