-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadv_num.c
More file actions
151 lines (124 loc) · 2.83 KB
/
adv_num.c
File metadata and controls
151 lines (124 loc) · 2.83 KB
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
138
139
140
141
142
143
144
145
146
147
148
149
150
#include "main.h"
/**
* _uns_prnt - function that prints unsigned numbers
* @tp: arguments
* @bffr: Array
* @flg: evaluates flags
* @wdt: breadth
* @prc: accuracy requirement
* @sz: Size indicator
* Return: counts of characters printed.
*/
int _uns_prnt(va_list tp, char bffr[], int flg, int wdt, int prc, int sz)
{
unsigned long int n = va_arg(tp, unsigned long int);
int ind = BUFFER_SIZE - 2;
n = us_cnvrt_sz(n, sz);
if (n == 0)
bffr[ind--] = '0';
bffr[BUFFER_SIZE - 1] = '\0';
while (n > 0)
{
bffr[ind--] = (n % 10) + '0';
n = n / 10;
}
ind++;
return (us_wrt(0, ind, bffr, flg, wdt, prc, sz));
}
/**
* _oct_prnt - prints octal numbers
* @tp: arguments
* @bffr: Array
* @flg: evaluates flags
* @wdt: breadth
* @prc: accuracy requirement
* @sz: Size indicator
* Return: count of characters printed
*/
int _oct_prnt(va_list tp, char bffr[], int flg, int wdt, int prc, int sz)
{
int ind = BUFFER_SIZE - 2;
unsigned long int n = va_arg(tp, unsigned long int);
unsigned long int num = n;
UNUSED(wdt);
n = us_cnvrt_sz(n, sz);
if (n == 0)
bffr[ind--] = '0';
bffr[BUFFER_SIZE - 1] = '\0';
while (n > 0)
{
bffr[ind--] = (n % 8) + '0';
n = n / 8;
}
if (flg & HSH && num != 0)
bffr[ind--] = '0';
ind++;
return (us_wrt(0, ind, bffr, flg, wdt, prc, sz));
}
/**
* _hex_prnt - prints in hexadecimal number
* @tp: arguments
* @bffr: array
* @flg: evaluates flags
* @wdt: breadth
* @prc: accuracy requirement
* @sz: Size indicator
* Return: count of characters printed
*/
int _hex_prnt(va_list tp, char bffr[], int flg, int wdt, int prc, int sz)
{
return (_hexa_prnt(tp, "0123456789abcdef", bffr, flg, 'x', wdt, prc,
sz));
}
/**
* _hex_upp_prnt - prints upper hexadecimal number
* @tp: arguments
* @bffr: Array
* @flg: evaluates flags
* @wdt: breadth
* @prc: accuracy requirement
* @sz: Size indicator
* Return: Count of characters printed
*/
int _hex_upp_prnt(va_list tp, char bffr[], int flg, int wdt, int prc, int sz)
{
return (_hexa_prnt(tp, "0123456789ABCDEF", bffr, flg, 'X', wdt, prc,
sz));
}
/**
* _hexa_prnt - prints a hexadecimal number
* @tp: arguments
* @dir_to: Array
* @bffr: array
* @flg: evaluates flags
* @ch_flg: evaluates flags
* @wdt: breadth
* @prc: accuracy requirement
* @sz: Size indicator
*
* Return: counts of printed characters
*/
int _hexa_prnt(va_list tp, char dir_to[], char bffr[], int flg, char ch_flg,
int wdt, int prc, int sz)
{
int ind = BUFFER_SIZE - 2;
unsigned long int n = va_arg(tp, unsigned long int);
unsigned long int num = n;
UNUSED(wdt);
n = us_cnvrt_sz(n, sz);
if (n == 0)
bffr[ind--] = '0';
bffr[BUFFER_SIZE - 1] = '\0';
while (n > 0)
{
bffr[ind--] = dir_to[n % 16];
n = n / 16;
}
if (flg & HSH && num != 0)
{
bffr[ind--] = ch_flg;
bffr[ind--] = '0';
}
ind++;
return (us_wrt(0, ind, bffr, flg, wdt, prc, sz));
}