-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprint_fcns2.c
137 lines (123 loc) · 1.81 KB
/
print_fcns2.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
#include "holberton.h"
/**
* pxx - print hexidecimal
* @valist: argument list
* Return: chars printed
*/
int pxx(va_list valist)
{
unsigned int n;
int k = 0, c = 0;
char hex[10];
n = va_arg(valist, unsigned int);
if (n == 0)
k += _putchar('0');
while (n != 0)
{
hex[c] = n % 16;
n /= 16;
c++;
}
c--;
while (c >= 0)
{
if (hex[c] >= 0 && hex[c] <= 9)
k += _putchar(hex[c] + '0');
else
{
k += _putchar((hex[c] % 10) + 'A');
}
c--;
}
return (k);
}
/**
* po - print unsigned octal
* @valist: argument list
* Return: chars printed
*/
int po(va_list valist)
{
unsigned int n;
int k = 0, c = 0, oct[10];
n = va_arg(valist, unsigned int);
if (n == 0)
k += _putchar('0');
while (n != 0)
{
oct[c] = n % 8;
n /= 8;
c++;
}
c--;
while (c >= 0)
{
if (oct[c] >= 0 && oct[c] < 9)
k += _putchar(oct[c] + '0');
c--;
}
return (k);
}
/**
* pp - print void pointer in hexidecimal
* @valist: argument list
* Return: chars printed
*/
int pp(va_list valist)
{
long int ptr, adr[16];
int k = 0, c = 0;
ptr = va_arg(valist, long int);
if (ptr == 0)
k += _putchar('0');
else
{
k += _putchar('0');
k += _putchar('x');
while (ptr != 0)
{
adr[c] = ptr % 16;
ptr /= 16;
c++;
}
c--;
while (c >= 0)
{
if (adr[c] >= 0 && adr[c] <= 9)
k += _putchar(adr[c] + '0');
else
{
k += _putchar((adr[c] % 10) + 'a');
}
c--;
}
}
return (k);
}
/**
* pb - print integer in binary
* @valist: argument list
* Return: chars printed
*/
int pb(va_list valist)
{
unsigned int n;
int k = 0, c = 0, bin[64];
n = va_arg(valist, unsigned int);
if (n == 0)
k += _putchar('0');
while (n != 0)
{
bin[c] = n % 2;
n /= 2;
c++;
}
c--;
while (c >= 0)
{
if (bin[c] >= 0 && bin[c] < 2)
k += _putchar(bin[c] + '0');
c--;
}
return (k);
}