-
Notifications
You must be signed in to change notification settings - Fork 0
/
customs.c
59 lines (51 loc) · 899 Bytes
/
customs.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
#include "main.h"
/**
* print_r - Prints the custom specifier r
* Strings are printed in reversed
* @s: String to print
* Return: count of string printed
*/
int print_r(char *s)
{
int count = 0;
int strcount = 0;
int j = 0;
if (s == NULL)
{
count += print_str("(nil)");
return (count);
}
while (s[j])
{
j++;
strcount++;
}
while (strcount)
count += print_char(s[strcount-- - 1]);
return (count);
}
/**
* print_R - Prints the custom specifier R
* ROT13 string is printed
* @s: string to print
* Return: count of strings printed
*/
int print_R(char *s)
{
int count = 0;
char c;
if (s == NULL)
{
count += print_str("(nil)");
return (count);
}
while ((c = *s++) != '\0')
{
if (c >= 'a' && c <= 'z')
c = ((c - 'a' + 13) % 26) + 'a';
else if (c >= 'A' && c <= 'Z')
c = ((c - 'A' + 13) % 26) + 'A';
count += print_char(c);
}
return (count);
}