-
Notifications
You must be signed in to change notification settings - Fork 0
/
simple_printers.c
executable file
·79 lines (73 loc) · 1.31 KB
/
simple_printers.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
#include "main.h"
/**
* print_from_to - prints a range of char addresses
* @start: starting address
* @stop: stopping address
* @except: except address
*
* Return: number 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 - prints string in reverse
* @ap: string
* @params: the parameters struct
*
* Return: number 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 - prints string in rot13
* @ap: string
* @params: the parameters struct
*
* Return: number 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);
}