-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_int.c
More file actions
42 lines (37 loc) · 716 Bytes
/
Copy pathprint_int.c
File metadata and controls
42 lines (37 loc) · 716 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
#include "main.h"
/**
* print_int - prints an integer
* @arguments: input string
* @buf: buffer pointer
* @ibuf: index for buffer pointer
* Return: number of chars printed.
*/
int print_int(va_list arguments, char *buf, unsigned int ibuf)
{
int int_input;
unsigned int int_in, int_temp, i, div, isneg;
int_input = va_arg(arguments, int);
isneg = 0;
if (int_input < 0)
{
int_in = int_input * -1;
ibuf = handl_buf(buf, '-', ibuf);
isneg = 1;
}
else
{
int_in = int_input;
}
int_temp = int_in;
div = 1;
while (int_temp > 9)
{
div *= 10;
int_temp /= 10;
}
for (i = 0; div > 0; div /= 10, i++)
{
ibuf = handl_buf(buf, ((int_in / div) % 10) + '0', ibuf);
}
return (i + isneg);
}