-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_string.c
95 lines (80 loc) · 1.44 KB
/
print_string.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
#include "main.h"
/**
* print_str - to print string charactar
* @arg: the argument of the integer function.
* Return: A total count of the characters printed.
*/
int print_str(va_list arg)
{
char *str;
int i = 0, length;
str = va_arg(arg, char *);
if (str == NULL)
{
str = "(null)";
}
length = _strlen(str);
while (i < length)
{
_putchar(str[i]);
i++;
}
return (length);
}
/**
* print_rev - prints an reversed string.
* @arg: the argument of the integer function..
* Return: A total count of the characters printed.
*/
int print_rev(va_list arg)
{
char *s = va_arg(arg, char *);
int j = 0;
int i;
if (s == NULL)
{
s = "(null)";
}
while (s[j] != '\0')
j++;
for (i = j - 1; i >= 0; i--)
{
_putchar(s[i]);
}
return (j);
}
/**
*print_rot13 - prints the rot13'ed string.
*@arg: the argument of the integer function..
*Return: A total count of the characters printed.
*/
int print_rot13(va_list arg)
{
int i, j;
int counter = 0;
int k = 0;
char *str = va_arg(arg, char *);
char alpha[] = { "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" };
char beta[] = { "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM" };
if (str == NULL)
str = "(null)";
for (i = 0; str[i] != '\0'; i++)
{
k = 0;
for (j = 0; alpha[j] && !k; j++)
{
if (str[i] == alpha[j])
{
_putchar(beta[j]);
counter++;
k = 1;
}
}
if (!k)
{
_putchar(str[i]);
counter++;
}
}
return (counter);
}