-
Notifications
You must be signed in to change notification settings - Fork 0
/
print_custom.c
108 lines (96 loc) · 2.11 KB
/
print_custom.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
#include "main.h"
/**
* print_bigS - Non printable characters
* (0 < ASCII value < 32 or >= 127) are
* printed this way: \x, followed by the ASCII code
* value in hexadecimal (upper case - always 2 characters)
* @l: va_list arguments from _printf
* @f: pointer to the struct flags that determines
* if a flag is passed to _printf
* Return: number of char printed
*/
int print_bigS(va_list l, flags_t *f)
{
int i, count = 0;
char *res;
char *s = va_arg(l, char *);
(void)f;
if (!s)
return (_puts("(null)"));
for (i = 0; s[i]; i++)
{
if (s[i] > 0 && (s[i] < 32 || s[i] >= 127))
{
_puts("\\x");
count += 2;
res = convert(s[i], 16, 0);
if (!res[1])
count += _putchar('0');
count += _puts(res);
}
else
count += _putchar(s[i]);
}
return (count);
}
/**
* print_rev - prints a string in reverse
* @l: argument from _printf
* @f: pointer to the struct flags that determines
* if a flag is passed to _printf
* Return: length of the printed string
*/
int print_rev(va_list l, flags_t *f)
{
int i = 0, j;
char *s = va_arg(l, char *);
(void)f;
if (!s)
s = "(null)";
while (s[i])
i++;
for (j = i - 1; j >= 0; j--)
_putchar(s[j]);
return (i);
}
/**
* print_rot13 - prints a string using rot13
* @l: list of arguments from _printf
* @f: pointer to the struct flags that determines
* if a flag is passed to _printf
* Return: length of the printed string
*/
int print_rot13(va_list l, flags_t *f)
{
int i, j;
char rot13[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char ROT13[] = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";
char *s = va_arg(l, char *);
(void)f;
for (j = 0; s[j]; j++)
{
if (s[j] < 'A' || (s[j] > 'Z' && s[j] < 'a') || s[j] > 'z')
_putchar(s[j]);
else
{
for (i = 0; i <= 52; i++)
{
if (s[j] == rot13[i])
_putchar(ROT13[i]);
}
}
}
return (j);
}
/**
* print_percent - prints a percent
* @l: va_list arguments from _printf
* @f: pointer to the struct flags in which we turn the flags on
* Return: number of char printed
*/
int print_percent(va_list l, flags_t *f)
{
(void)l;
(void)f;
return (_putchar('%'));
}