-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path3fprint.c
68 lines (63 loc) · 1.02 KB
/
3fprint.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
#include "main.h"
/**
* print_o - converts unsigned int to usnsigned octal
* @list: input list of values
* Return: count.
*/
int print_o(va_list list)
{
unsigned int buf[10];
unsigned int i, m, num;
int count;
unsigned int sum = 0;
num = va_arg(list, unsigned int);
m = expo(8, 10);
buf[0] = (num / m);
for (i = 1; i <= 10; i++)
{
m /= 8;
buf[i] = (num / m) % 8;
}
for (i = 0; i <= 10; i++)
{
count = 0;
sum += buf[i];
if (sum || i == 10)
{
_write_ch('0' + buf[i]);
count++;
}
}
return (count);
}
/**
* print_u - converts unsigned int to decimal
* @list: input list of values
* Return: count.
*/
int print_u(va_list list)
{
unsigned int buf[10];
unsigned int i, m, num;
unsigned int sum = 0;
int count;
num = va_arg(list, unsigned int);
m = expo(10, 9);
buf[0] = (num / m);
for (i = 1; i < 10; i++)
{
m /= 10;
buf[i] = (num / m) % 10;
}
for (i = 0; i < 10; i++)
{
count = 0;
sum += buf[i];
if (sum || i == 9)
{
_write_ch('0' + buf[i]);
count++;
}
}
return (count);
}