-
Notifications
You must be signed in to change notification settings - Fork 0
/
arg_nbr_functions.c
executable file
·90 lines (76 loc) · 1.36 KB
/
arg_nbr_functions.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
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
#include "main.h"
#include <stdarg.h>
#include <stdlib.h>
/**
* print_nbr - print number
* @ap: arg list
* Return: number of printed char
*/
int print_nbr(va_list ap)
{
return (print_number(va_arg(ap, int)));
}
/**
* print_binary - print number binary base
* @ap: arg list
* Return: number of printed char
*/
int print_binary(va_list ap)
{
char *str;
int sum = 0;
unsigned int argument = va_arg(ap, unsigned int);
if (!argument)
{
sum += _puts("0", 0);
return (sum);
}
str = convert_base(argument, 2, 0);
if (!str)
return (0);
sum = _puts(str, 0);
free(str);
return (sum);
}
/**
* print_octal - print number octal base
* @ap: arg list
* Return: number of printed char
*/
int print_octal(va_list ap)
{
char *str;
int sum;
str = convert_base(va_arg(ap, unsigned int), 8, 0);
sum = _puts(str, 0);
free(str);
return (sum);
}
/**
* print_hexa_lower - print hexa lower
* @ap: arg list
* Return: number of printed char
*/
int print_hexa_lower(va_list ap)
{
char *str;
int sum;
str = convert_base(va_arg(ap, unsigned int), 16, 0);
sum = _puts(str, 0);
free(str);
return (sum);
}
/**
* print_hexa_upper - print hexa upper
* @ap: arg list
* Return: number of printed char
*/
int print_hexa_upper(va_list ap)
{
char *str;
int sum;
str = convert_base(va_arg(ap, unsigned int), 16, 1);
sum = _puts(str, 0);
free(str);
return (sum);
}