-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy path_put_Lnum.c
52 lines (48 loc) · 913 Bytes
/
_put_Lnum.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
#include "main.h"
/**
* _print_long - prints a number to stdout
* @num: the number to print
* @flags: struct that contains the flags to use
* Return: the number of characters printed
*/
int _print_long(long num, flags_t flags)
{
int count = 0;
if (flags.h == 1)
num = (short)num;
else if (flags.h == 2)
num = (char)num;
else if (flags.l == 1)
num = (long)num;
if (num == -2147483648)
{
count += _putstr("-2147483648");
return (count);
}
if (flags.plus && num >= 0)
count += _putchar('+');
else if (flags.space && num >= 0)
count += _putchar(' ');
if (num < 0)
{
count += _putchar('-');
num = -num;
}
if (num == 0)
count += _putchar('0');
else
{
char num_str[21];
int i = 0;
while (num != 0)
{
num_str[i] = (num % 10) + '0';
num /= 10;
i++;
}
num_str[i] = '\0';
for (i = i - 1; i >= 0; i--)
count += _putchar(num_str[i]);
}
return (count);
}