-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunction_1.c
More file actions
160 lines (132 loc) · 3.58 KB
/
function_1.c
File metadata and controls
160 lines (132 loc) · 3.58 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
151
152
153
154
155
156
157
158
159
160
#include "main.h"
/* PRINTING AN UNSIGNED NUMBER */
/**
* unsigned_print - Function prints an unsigned number
* @type: argument list
* @buff: An array handling printing
* @flag: variable calculating flags that are active
* @width: Width
* @prec: specifies precision
* @size: specifies size
* Return: size of characters to print
*/
int unsigned_print(va_list type, char buff[],
int flag, int width, int prec, int size)
{
int x = BUFF_SIZE - 2;
unsigned long int n = va_arg(type, unsigned long int);
n = convert_size_unsgnd(n, size);
if (n == 0)
buff[x--] = '0';
buff[BUFF_SIZE - 1] = '\0';
while (n > 0)
{
buff[x--] = (n % 10) + '0';
n /= 10;
}
x++;
return (write_unsgnd(0, x, buff, flag, width, prec, size));
}
/* PRINTING AN UNSIGNED NUMBER IN OCTAL */
/**
* octal_print - Function prints an unsigned number in octal
* @type: argument list
* @buff: An array handling printing
* @flag: variable calculating flags that are active
* @width: Width
* @prec: specifies precision
* @size: specifies size
* Return: size of characters to print
*/
int octal_print(va_list type, char buff[],
int flag, int width, int prec, int size)
{
int x = BUFF_SIZE - 2;
unsigned long int n = va_arg(type, unsigned long int);
unsigned long int init_number = n;
UNUSED(width);
n = convert_size_unsgnd(n, size);
if (n == 0)
buff[x--] = '0';
buff[BUFF_SIZE - 1] = '\0';
while (n > 0)
{
buff[x--] = (n % 8) + '0';
n /= 8;
}
if (flag & FLAG_HASH && init_number != 0)
buff[x--] = '0';
x++;
return (write_unsgnd(0, x, buff, flag, width, prec, size));
}
/* PRINTING AN UNSIGNED NUMBER IN HEXADECIMAL */
/**
* hexadecimal_print - Function prints an unsigned number in hexadecimal
* @type: argument list
* @buff: An array handling printing
* @flag: variable calculating flags that are active
* @width: Width
* @prec: specifies precision
* @size: specifies size
* Return: size of characters to print
*/
int hexadecimal_print(va_list type, char buff[],
int flag, int width, int prec, int size)
{
return (print_hexa(type, "0123456789abcdef", buff,
flag, 'x', width, prec, size));
}
/* PRINTING AN UNSIGNED NUMBER IN UPPER HEXADECIMAL */
/**
* hexa_upper_print - Function prints in upper hexadecimal
* @type: argument list
* @buff: An array handling printing
* @flag: variable calculating flags that are active
* @width: Width
* @prec: specifies precision
* @size: specifies size
* Return: size of characters to print
*/
int hexa_upper_print(va_list type, char buff[],
int flag, int width, int prec, int size)
{
return (print_hexa(type, "0123456789ABCDEF", buff,
flag, 'X', width, prec, size));
}
/* PRINTING HEXADECIMAL NUMBER IN LOWERCASE OR UPPERCASE */
/**
* print_hexa - Prints a hexadecimal number in lower or upper
* @type: arguments List
* @map_to: value array mapping the number to
* @buff: Buffer array handling print
* @flag: Calculates active flags
* @flag_char: active flags calculator
* @width: width
* @prec: specifies precision
* @size: specifies size
* Return: size of characters to print
*/
int print_hexa(va_list type, char map_to[], char buff[],
int flag, char flag_char, int width, int prec, int size)
{
int x = BUFF_SIZE - 2;
unsigned long int n = va_arg(type, unsigned long int);
unsigned long int init_number = n;
UNUSED(width);
n = convert_size_unsgnd(n, size);
if (n == 0)
buff[x--] = '0';
buff[BUFF_SIZE - 1] = '\0';
while (n > 0)
{
buff[x--] = map_to[n % 16];
n /= 16;
}
if (flag & FLAG_HASH && init_number != 0)
{
buff[x--] = flag_char;
buff[x--] = '0';
}
x++;
return (write_unsgnd(0, x, buff, flag, width, prec, size));
}