-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_nums.c
102 lines (80 loc) · 1.47 KB
/
print_nums.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
#include "main.h"
#include <stdio.h>
/**
* handle_d - prints decimal integers
*
* @d: the number to be printed
* Return: the count of digits printed.
*/
int handle_d(va_list d)
{
int num, count = 0;
char tmp[100];
num = va_arg(d, int);
if (num == 0)
{
return (_puts("0"));
}
if (num < 0)
{
num *= -1;
count += _puts("-");
}
convert_bases(((unsigned int) num), tmp, 10, 0);
count += _puts(tmp);
return (count);
}
/**
* handle_oct - prints decimal numbers in octal
*
* @oct: the decimal number to be printed in octal
* Return: the count of digits printed.
*/
int handle_oct(va_list oct)
{
char tmp[100];
int num = 0;
num = va_arg(oct, unsigned int);
if (num == 0)
{
return (_puts("0"));
}
convert_bases(((unsigned int) num), tmp, 8, 0);
return (_puts(tmp));
}
/**
* handle_b - prints decimal numbers in binary
*
* @b: the decimal number to be printed in binary
* Return: the count of digits printed.
*/
int handle_b(va_list b)
{
char tmp[100];
int num = 0;
num = va_arg(b, unsigned int);
if (num == 0)
{
return (_puts("0"));
}
convert_bases(((unsigned int) num), tmp, 2, 0);
return (_puts(tmp));
}
/**
* handle_u - print unsigned decimal integers
*
* @u: the number to be printed
* Return: the count of digits printed.
*/
int handle_u(va_list u)
{
char tmp[100];
int num = 0;
num = va_arg(u, unsigned int);
if (num == 0)
{
return (_puts("0"));
}
convert_bases(((unsigned int) num), tmp, 10, 0);
return (_puts(tmp));
}