-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathprint_rot.c
41 lines (38 loc) · 835 Bytes
/
print_rot.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
#include "main.h"
/**
* print_rot - writes the str in ROT13
* @arguments: input string
* @buf: buffer pointer
* @ibuf: index for buffer pointer
* Return: number of chars printed.
*/
int print_rot(va_list arguments, char *buf, unsigned int ibuf)
{
char alf[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char rot[] = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
char *str;
unsigned int i, j, k;
char nill[] = "(avyy)";
str = va_arg(arguments, char *);
if (str == NULL)
{
for (i = 0; nill[i]; i++)
ibuf = handl_buf(buf, nill[i], ibuf);
return (6);
}
for (i = 0; str[i]; i++)
{
for (k = j = 0; alf[j]; j++)
{
if (str[i] == alf[j])
{
k = 1;
ibuf = handl_buf(buf, rot[j], ibuf);
break;
}
}
if (k == 0)
ibuf = handl_buf(buf, str[i], ibuf);
}
return (i);
}