-
Notifications
You must be signed in to change notification settings - Fork 0
/
14-functions.c
43 lines (40 loc) · 905 Bytes
/
14-functions.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
#include "main.h"
/**
* print_rot - Prints string in rot13 encoding
*
* @arg_list: Input integers argument (int)
* @buffer: Buffer array (char)
* @index: Number of buffer index (int)
*
* Return: The length of a rot13 numbers
*/
int print_rot(va_list arg_list, char *buffer, unsigned int index)
{
char letter[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char rot[] = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
char *str;
unsigned int i, j, k;
char none[] = "(avyy)";
str = va_arg(arg_list, char *);
if (str == NULL)
{
for (i = 0; none[i]; i++)
index = _puts(buffer, none[i], index);
return (6);
}
for (i = 0; str[i]; i++)
{
for (k = j = 0; letter[j]; j++)
{
if (str[i] == letter[j])
{
k = 1;
index = _puts(buffer, rot[j], index);
break;
}
}
if (k == 0)
index = _puts(buffer, str[i], index);
}
return (i);
}