-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions3.c
More file actions
85 lines (74 loc) · 1.23 KB
/
functions3.c
File metadata and controls
85 lines (74 loc) · 1.23 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
#include "main.h"
/**
* print_unsigned - prints unsigned integer
* @args: argument list
*
* Return: number of printed characters
*/
int print_unsigned(va_list args)
{
unsigned int num = va_arg(args, unsigned int);
unsigned int num_cp = num;
char *num_str;
int i, size = 0;
if (num == 0)
{
_putchar('0');
return (1);
}
while (num_cp)
{
size++;
num_cp /= 10;
}
num_str = (char *)malloc(sizeof(char) * size);
if (num_str == NULL)
{
return (-1);
}
i = size - 1;
while (num)
{
num_str[i] = '0' + (num % 10);
num /= 10;
i--;
}
i = 0;
while (i < size)
{
_putchar(num_str[i]);
i++;
}
free(num_str);
return (size);
}
/**
* print_octal - prints octal numbers
* @args: argument list
*
* Return: number of printed charactes
*/
int print_octal(va_list args)
{
return (convert_to_base(args, 8, 'o'));
}
/**
* print_hex - prints hexadecimal numbers in lower case
* @args: argument list
*
* Return: number of printed characters
*/
int print_hex(va_list args)
{
return (convert_to_base(args, 16, 'x'));
}
/**
* print_HEX - prints hexadecimal in uppuercase
* @args: argument list
*
* Return: number of printed characters
*/
int print_HEX(va_list args)
{
return (convert_to_base(args, 16, 'X'));
}