-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple_printers.c
More file actions
81 lines (74 loc) · 1.43 KB
/
Copy pathsimple_printers.c
File metadata and controls
81 lines (74 loc) · 1.43 KB
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
#include "main.h"
/**
* print_from_to - Print characters from start to stop,
* excluding the "except" character.
* @start: Starting address.
* @stop: Stopping address.
* @except: Address to be excluded.
*
* Return: Number of bytes printed.
*/
int print_from_to(char *start, char *stop, char *except)
{
int sum = 0;
while (start <= stop)
{
if (start != except)
sum += _putchar(*start);
start++;
}
return (sum);
}
/**
* print_rev - Print a string in reverse order.
* @ap: String to be printed.
* @params: Parameters structure.
*
* Return: Number of bytes printed.
*/
int print_rev(va_list ap, params_t *params)
{
int len, sum = 0;
char *str = va_arg(ap, char *);
(void)params;
if (str)
{
for (len = 0; *str; str++)
len++;
str--;
for (; len > 0; len--, str--)
sum += _putchar(*str);
}
return (sum);
}
/**
* print_rot13 - Print a string using the ROT13 encoding.
* @ap: String to be printed.
* @params: Parameters structure.
*
* Return: Number of bytes printed.
*/
int print_rot13(va_list ap, params_t *params)
{
int i, index;
int count = 0;
char arr[] =
"NOPQRSTUVWXYZABCDEFGHIJKLM nopqrstuvwxyzabcdefghijklm";
char *a = va_arg(ap, char *);
(void)params;
i = 0;
index = 0;
while (a[i])
{
if ((a[i] >= 'A' && a[i] <= 'Z')
|| (a[i] >= 'a' && a[i] <= 'z'))
{
index = a[i] - 65;
count += _putchar(arr[index]);
}
else
count += _putchar(a[i]);
i++;
}
return (count);
}