-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathprint_integer.c
More file actions
54 lines (43 loc) · 747 Bytes
/
print_integer.c
File metadata and controls
54 lines (43 loc) · 747 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
46
47
48
49
50
51
52
53
54
#include "main.h"
/**
* print_integer - Prints an integer
* @list: list of arguments
* Return: Will return the amount of characters printed.
*/
int print_integer(va_list list)
{
int num_length;
num_length = print_number(list);
return (num_length);
}
/**
* print_number - prints a number send to this function
* @args: List of arguments
* Return: The number of arguments printed
*/
int print_number(va_list args)
{
int n;
int div;
int len;
unsigned int num;
n = va_arg(args, int);
div = 1;
len = 0;
if (n < 0)
{
len += _putchar('-');
num = n * -1;
}
else
num = n;
for (; num / div > 9; )
div *= 10;
for (; div != 0; )
{
len += _putchar('0' + num / div);
num %= div;
div /= 10;
}
return (len);
}