-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprint_uint.c
More file actions
45 lines (39 loc) · 756 Bytes
/
print_uint.c
File metadata and controls
45 lines (39 loc) · 756 Bytes
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
#include "main.h"
/**
* print_uint - print unsigned numbers that more than 1 digit.
*
* @arg: number to be processed.
* @flag: flags to be considered in printing.
*
* Return: number of printed chars.
*/
int print_uint(va_list arg, flags_t *flag)
{
int len = 0, last, index, digit, base = 1;
int tempi;
unsigned int num = va_arg(arg, unsigned int);
(void) flag;
if (num == 0)
{
_putchar(0 + '0');
return (1);
}
last = num % 10;
len = num_of_digits(num);
if (len > 1)
{
for (index = 1; index < len; index++)
{
for (tempi = len - index; tempi != 0; tempi--)
{
base = base * 10;
}
digit = num / (base);
digit = digit % 10;
_putchar(digit + '0');
base = 1;
}
}
_putchar(last + '0');
return (len);
}