-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconversion_funcs.c
118 lines (98 loc) · 2.71 KB
/
conversion_funcs.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <stdio.h>
#include <stdarg.h>
#include "main.h"
/**
* cvt_c - handle character printing
* @ap: stores argument list
* @flags: pointer to flags in the format string
* @width: width given in the format string
* @precision: precision given in the format string
* Return: number of characters printed
*/
int cvt_c(va_list ap, unsigned char flags[], int width, int precision)
{
int num_of_char = 0;
(void)flags;
(void)width;
(void)precision;
num_of_char += _putchar((unsigned char)va_arg(ap, int));
return (num_of_char);
}
/**
* cvt_s - prints string
* @ap: stores argument list
* @flags: pointer to flags in the format string
* @width: width given in the format string
* @precision: precision given in the format string
* Return: number of characters printed
*/
int cvt_s(va_list ap, unsigned char flags[], int width, int precision)
{
unsigned int num_of_char;
char *str = va_arg(ap, char *);
if (!str)
str = "(null)";
num_of_char = _puts(str, flags, width, precision);
return (num_of_char);
}
/**
* cvt_d - handle base 10 digit printing
* @ap:Stoe arguments list
* @flags: pointer to flags in the format string
* @width: width given in the format string
* @precision: precision given in the format string
* Return: number of characters printed
*/
int cvt_d(va_list ap, unsigned char flags[], int width, int precision)
{
int num_of_char = 0;
int decimal_num = va_arg(ap, int);
char *digits;
if (decimal_num < 0)
{
decimal_num = -decimal_num;
num_of_char += _putchar('-');
}
digits = base_convert(decimal_num, 10);
num_of_char += _putd(digits, flags, width, precision);
return (num_of_char);
}
/**
* cvt_i - handle integers printing
* @ap: Store arguments list
* @flags: pointer to flags in the format string
* @width: width given in the format string
* @precision: precision given in the format string
* Return: number of characters printed
*/
int cvt_i(va_list ap, unsigned char flags[], int width, int precision)
{
int num_of_char = 0;
int decimal_num = va_arg(ap, int);
char *digits;
if (decimal_num < 0)
{
decimal_num = -decimal_num;
num_of_char += _putchar('-');
}
digits = base_convert(decimal_num, 10);
num_of_char += _putd(digits, flags, width, precision);
return (num_of_char);
}
/**
* cvt_b - handle binary printing
* @ap: Store arguments list
* @flags: pointer to flags in the format string
* @width: width given in the format string
* @precision: precision given in the format string
* Return: number of characters printed
*/
int cvt_b(va_list ap, unsigned char flags[], int width, int precision)
{
int num_of_char = 0;
int decimal_num = va_arg(ap, int);
char *digits;
digits = base_convert(decimal_num, 2);
num_of_char += _putd(digits, flags, width, precision);
return (num_of_char);
}