forked from Brexblime/printf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_r13.c
More file actions
39 lines (36 loc) · 718 Bytes
/
Copy pathprint_r13.c
File metadata and controls
39 lines (36 loc) · 718 Bytes
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
#include "main.h"
/**
* print_rot13 - prints a string to ROT13 and places it into a buffer
* @arg: struct va_arg where printf arguments are allocated
*
* Return: counter
*/
int print_rot13(va_list arg)
{
int i, j, counter = 0;
int k = 0;
char *s = va_arg(arg, char*);
char alpha[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char beta[] = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";
if (s == NULL)
s = "(null)";
for (i = 0; s[i]; i++)
{
k = 0;
for (j = 0; alpha[j] && !k; j++)
{
if (s[i] == alpha[j])
{
_putchar(beta[j]);
counter++;
k = 1;
}
}
if (!k)
{
_putchar(s[i]);
counter++;
}
}
return (counter);
}