-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprinthexa.c
More file actions
65 lines (61 loc) · 1.33 KB
/
printhexa.c
File metadata and controls
65 lines (61 loc) · 1.33 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
#include "holberton.h"
/**
* print_hexa_lower_case - print hexa letters lowercase
* @valist: valist
* @opt: option to print
* Return: count of bytes printed
*/
int print_hexa_lower_case(va_list valist, options opt)
{
char *str;
int bytes = 0;
(void) opt;
str = unsigned_number_to_string(va_arg(valist, unsigned int), 16);
if (str == NULL)
{
return (_putchar("(null)", str_length("(null)")));
}
bytes = _putchar(str, str_length(str));
free(str);
return (bytes);
}
/**
* print_hexa_upper_case - print hexa in upper case
* @valist: valist
* @opt: option to print
* Return: count of bytes printed
*/
int print_hexa_upper_case(va_list valist, options opt)
{
char *str;
int bytes = 0;
(void) opt;
str = unsigned_number_to_string(va_arg(valist, unsigned int), 17);
if (str == NULL)
{
return (_putchar("(null)", str_length("(null)")));
}
bytes = _putchar(str, str_length(str));
free(str);
return (bytes);
}
/**
* print_octal - print number in octal
* @valist: valist
* @opt: option to print
* Return: count of bytes printed
*/
int print_octal(va_list valist, options opt)
{
char *str;
int bytes = 0;
(void) opt;
str = unsigned_number_to_string(va_arg(valist, unsigned int), 8);
if (str == NULL)
{
return (_putchar("(null)", str_length("(null)")));
}
bytes = _putchar(str, str_length(str));
free(str);
return (bytes);
}