-
Notifications
You must be signed in to change notification settings - Fork 0
/
0-printf.c
executable file
·104 lines (94 loc) · 1.83 KB
/
0-printf.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
#include "main.h"
/**
* print_character - prints character
* @arg: va_list parameter
* Description: print character
* Return: 1
*/
int print_character(va_list arg)
{
int i;
i = va_arg(arg, int);
_putchar(i);
return (1);
}
/**
* print_sign - print sign
* @arg: va_list parameter
* @base: base 10, 8, 16, 2 etc..
* Description: print numbers and signed
* Return: num of characters
*/
int print_sign(va_list arg, int base)
{
int i = 0, cont = 0;
char *s;
i = va_arg(arg, int);
if (i < 0)
{
i = -(i);
_putchar('-');
cont += 1;
}
s = convert_to("0123456789ABCDEF", i, base);
_puts(s);
cont += _strlen(s);
return (cont);
}
/**
* print_unsign - print_unsign
* @arg: va_list parameter
* @base: base 10, 8, 16 etc..
* Description: print numbers without signed
* Return: num of characters
*/
int print_unsign(va_list arg, int base)
{
int cont = 0;
unsigned int i;
char *s;
i = va_arg(arg, unsigned int);
s = convert_to("0123456789ABCDEF", i, base);
_puts(s);
cont = _strlen(s);
return (cont);
}
/**
* print_string - print string
* @arg: va_list parameter
* Description: print string
* Return: num of characters
*/
int print_string(va_list arg)
{
char *s;
int cont = 0;
s = va_arg(arg, char *);
if (!s)
{
s = "(null)";
_puts(s);
return (_strlen(s));
}
_puts(s);
cont = _strlen(s);
return (cont);
}
/**
* print_base16_upper_lower - print_base16_upper_lower
* @arg: va_list parameter
*@representation: pointer parameter
* Description: This function takes 0123456789ABCDEF or 0123456789abcdef
* in representation parameter for print hexadecimal format
* Return: num of characters
*/
int print_base16_upper_lower(va_list arg, char *representation)
{
unsigned int i = 0, cont = 0;
char *s;
i = va_arg(arg, unsigned int);
s = convert_to(representation, i, 16);
_puts(s);
cont = _strlen(s);
return (cont);
}