-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path2-functions.c
More file actions
107 lines (99 loc) · 1.55 KB
/
2-functions.c
File metadata and controls
107 lines (99 loc) · 1.55 KB
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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
#include "main.h"
/**
* octal - change base 8
* @list: contains arguments
* Return: length
*/
int octal(va_list list)
{
unsigned int x = va_arg(list, unsigned int);
int y;
y = octal1(x);
return (y);
}
/**
* hexa_upper - prints number in upper hexadecimal
* @list: contains arguments
* Return: length
*/
int hexa_upper(va_list list)
{
unsigned long int x = va_arg(list, unsigned long int);
int y;
y = hex_upper(x);
return (y);
}
/**
* hexa_lower - prints number in upper hexadecimal
* @list: contains arguments
* Return: length
*/
int hexa_lower(va_list list)
{
unsigned long int x = va_arg(list, unsigned long int);
int y;
y = hex_low(x);
return (y);
}
/**
* octal1 - convert to base 8
* @n: number
* Return: length
*/
int octal1(unsigned int n)
{
int i, *arr, count = 0;
unsigned int num;
num = n;
while (n / 8 != 0)
{
n /= 8;
count++;
}
count++;
arr = malloc(sizeof(int) * count);
if (arr == NULL)
return (0);
for (i = 0; i < count; i++)
{
arr[i] = num % 8;
num = num / 8;
}
for (i = count - 1; i >= 0; i--)
{
_putchar(arr[i] + '0');
}
free(arr);
return (count);
}
/**
* _unsign - convert to base 8
* @n: number
* Return: length
*/
int _unsign(unsigned int n)
{
int i, *arr, count = 0;
unsigned int num;
num = n;
while (n / 10 != 0)
{
n /= 10;
count++;
}
count++;
arr = malloc(sizeof(int) * count);
if (arr == NULL)
return (0);
for (i = 0; i < count; i++)
{
arr[i] = num % 10;
num = num / 10;
}
for (i = count - 1; i >= 0; i--)
{
_putchar(arr[i] + '0');
}
free(arr);
return (count);
}