forked from AnasBenba/printf
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path_put_Lo.c
45 lines (42 loc) · 766 Bytes
/
_put_Lo.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
#include "main.h"
/**
* _put_Lo - Prints an unsigned long int argument as an octal number
* @nb: The number to print
* @flags: struct that contains the flags to use
* Return: The number of characters printed
*/
int _put_Lo(unsigned long int nb, flags_t flags)
{
unsigned long int octal[22];
int i, j, count;
i = 0;
j = 0;
count = 0;
if (flags.h == 1)
nb = (unsigned short)nb;
else if (flags.h == 2)
nb = (unsigned char)nb;
else if (flags.l == 1)
nb = (unsigned long)nb;
while (nb > 0)
{
octal[i] = nb % 8;
nb /= 8;
i++;
}
if (i == 0)
{
_putchar('0');
return (1);
}
j = i - 1;
if (flags.hash && octal[j] != 0)
count += _putchar('0');
while (j >= 0)
{
_putchar(octal[j] + '0');
count++;
j--;
}
return (count);
}