-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathroot13.c
More file actions
42 lines (41 loc) · 908 Bytes
/
root13.c
File metadata and controls
42 lines (41 loc) · 908 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
39
40
41
42
#include "holberton.h"
/**
* print_rot13 - print with rot13
* @valist: valist
* @opt: option to print
* Return: count of bytes printed
*/
int print_rot13(va_list valist, options opt)
{
int iterator, bytes;
int ikeys = 0;
char keys[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char values[] = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
char *aux;
char *str = va_arg(valist, char*);
int flag = 1;
(void) opt;
if (str == NULL)
{
return (_putchar("(null)", str_length("(null)")));
}
aux = malloc((str_length(str) + 1) * sizeof(char));
for (iterator = 0; str[iterator]; iterator++)
{
while (keys[ikeys] && flag)
{
if (str[iterator] == keys[ikeys])
{
aux[iterator] = values[ikeys];
flag = 0;
}
ikeys++;
}
ikeys = 0;
flag = 1;
}
aux[iterator] = str[iterator];
bytes = _putchar(aux, str_length(str));
free(aux);
return (bytes);
}