-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_printf1.c
137 lines (130 loc) · 3.59 KB
/
_printf1.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 "main.h"
/***** UNSIGNED NUM TO BE PRINTED *****/
/**
* _print_unsigned - function to print unsigned num
* @a: arguements
* @buffer: an array to hold print
* @width: specifier
* @flags: it calculates current flags
* @precision: for spercification
* @size: length specifier
* Return: character number to be printed
*/
int _print_unsigned(va_list a, char buffer[], int flags,
int width, int precision, int size)
{
int k = BUFF_SIZE - 2;
unsigned long int number = va_arg(a, unsigned long int);
number = convert_unsg(number, size);
if (number == 0)
buffer[k] = '\0';
while (number > 0)
{
buffer[k--] = (number % 10) + '0';
number /= 10;
}
k++;
return (write_unsg(0, k, buffer, flags, width, precision, size));
}
/***** OCTAL UNSIGNED NUM TO PRINT *****/
/**
* _print_octal - function to print unsigned octal notation
* @a: arguements
* @flags: to calculate the current flags
* @buffer: an array that handle print
* @precision: for specifying
* @width: specifier
* @size: length specifier
* Return: characters to be printed
*/
int _print_octal(va_list a, char buffer[], int flags,
int width, int precision, int size)
{
int k = BUFF_SIZE - 2;
unsigned long int number = va_arg(a, unsigned long int);
unsigned long int init_number = number;
UNUSED(width);
number = convert_unsg(number, size);
if (number == 0)
buffer[k--] = '\0';
while (number > 0)
{
buffer[k--] = (number % 8) + '0';
number /= 8;
}
if (flags & FL_HASH && init_number != 0)
buffer[k++] = '0';
k++;
return (write_unsg(0, k, buffer, flags, width, precision, size));
}
/**** PRINTING UNSIGNED NUM IN HEX ******/
/**
* _print_hex - function to print unsuigned num in hex
* @a: the list of arguements
* @buffer: an array to hold print
* @flags: to calculate the current flags
* @width: specifier
* @precision: for specifying
* @size: length specifier
* Return: character to be printed
*/
int _print_hex(va_list a, char buffer[], int flags,
int width, int precision, int size)
{
return (_print_hexa(a, "0123456789abcdef", buffer, flags,
'x', width, precision, size));
}
/****** PRINTING UNSIGNED NUM IN UPPER HEXA ******/
/**
* _print_hex_upper - function to print unsigned num in upp hex
* @buffer: it holds an array to print
* @a: arguements
* @flags: to calculate the current flags
* @width: specifier
* @precision: for specifying
* @size: length specifier
* Return: characters to be printed
*/
int _print_hex_upper(va_list a, char buffer[], int flags,
int width, int precision, int size)
{
return (_print_hexa(a, "0123456789ABCDEF",
buffer, flags, 'X', width, precision, size));
}
/*** PRINTING HEXA IN LOWER OR UPPER ****/
/**
* _print_hexa - funtion to print hex num in lower or upper
* @a: Arguements
* @m_t: this is array to map value to a number
* @buffer: this holds an array to print
* @flags: to calculate the current flags
* @width: specifier
* @flags_sh: to calculate the active flags
* @precision: for specifying
* @size: specifier
* @size: for specifying
* Return: characters to print
*/
int _print_hexa(va_list a, char m_t[], char buffer[], int flags,
char flags_sh, int width, int precision, int size)
{
int k = BUFF_SIZE - 2;
unsigned long int number = va_arg(a, unsigned long int);
unsigned long int init_number = number;
UNUSED(width);
number = convert_unsg(number, size);
if (number == 0)
buffer[k--] = '0';
buffer[BUFF_SIZE - 1] = '\0';
while (number > 0)
{
buffer[k--] = m_t[number % 16];
}
if (flags & FL_HASH && init_number != 0)
{
buffer[k--] = flags_sh;
buffer[k--] = '0';
}
k++;
return (write_unsg(0, k, buffer, flags, width, precision, size));
}