-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path1-functions.c
84 lines (73 loc) · 1.51 KB
/
1-functions.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
#include "main.h"
/**
* print_integer - Prints an integer
*
* @arg_list: Input integers argument (int)
* @buffer: Buffer array (char)
* @index: Number of buffer index (int)
*
* Return: The length of integers
*/
int print_integer(va_list arg_list, char *buffer, unsigned int index)
{
int number = va_arg(arg_list, int);
unsigned int num, num_stored, i, diviser, negative_checker = 0;
if (number < 0)
{
num = number * -1;
index = _puts(buffer, '-', index);
negative_checker = 1;
}
else
{
num = number;
}
num_stored = num;
diviser = 1;
while (num_stored > 9)
{
diviser *= 10;
num_stored /= 10;
}
for (i = 0; diviser > 0; diviser /= 10, i++)
{
index = _puts(buffer, ((num / diviser) % 10) + '0', index);
}
return (i + negative_checker);
}
/**
* print_digit - Prints a digit
*
* @arg_list: Input digits argument (int)
* @buffer: Buffer array (char)
* @index: Number of buffer index (int)
*
* Return: The length of digits
*/
int print_digit(va_list arg_list, char *buffer, unsigned int index)
{
int number = va_arg(arg_list, int);
unsigned int num, num_stored, i, diviser, negative_checker = 0;
if (number < 0)
{
num = number * -1;
index = _puts(buffer, '-', index);
negative_checker = 1;
}
else
{
num = number;
}
num_stored = num;
diviser = 1;
while (num_stored > 9)
{
diviser *= 10;
num_stored /= 10;
}
for (i = 0; diviser > 0; diviser /= 10, i++)
{
index = _puts(buffer, ((num / diviser) % 10) + '0', index);
}
return (i + negative_checker);
}