-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandle_di.c
More file actions
78 lines (62 loc) · 1.06 KB
/
handle_di.c
File metadata and controls
78 lines (62 loc) · 1.06 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
66
67
68
69
70
71
72
73
74
75
76
77
78
#include "main.h"
/**
* get_int - function that recursively prints an integer
* and print its digit in correct order
* @num: the integer to check
*
* Return: the digit in correct order
*/
int get_int(int num)
{
int n, r_value = 0;
/* check if num is 0 */
if (!num)
{
_putchar(0 + '0');
r_value++;
return (r_value);
}
/* check for negative value */
else if (num < 0)
{
_putchar('-');
r_value++;
num = -num;
}
n = num / 10;
if (n != 0)
{
r_value += get_int(n);
}
_putchar(num % 10 + '0');
r_value++;
return (r_value);
}
/**
* handle_di - handles the specifiers, 'd' and 'i'
* @di: the variable argument(s) passed to _printf
*
* Return: the number of character(s) printed
*/
int handle_di(va_list di)
{
int r_value = 0;
int de_int = va_arg(di, int);
if (de_int == INT_MIN)
{
_putchar('-');
_putchar('2');
_putchar('1');
_putchar('4');
_putchar('7');
_putchar('4');
_putchar('8');
_putchar('3');
_putchar('6');
_putchar('4');
_putchar('8');
return (11);
}
r_value = get_int(de_int);
return (r_value);
}