-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrot13.c
More file actions
executable file
·38 lines (37 loc) · 757 Bytes
/
rot13.c
File metadata and controls
executable file
·38 lines (37 loc) · 757 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 "holberton.h"
/**
* printR13 - Encodes string into rot13
* @s: Target String.
*
* Return: Encoded string.
*/
int printR13(va_list s)
{
int i, j, len = 0;
char chs[] = {"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"};
char rot13[] = {"NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm"};
char *str, *str2;
str = va_arg(s, char *);
for (i = 0; str[i] != '\0'; i++)
len++;
str2 = malloc(sizeof(char) * len + 1);
if (!str2)
return ('\0');
for (i = 0; i <= len; i++)
str2[i] = str[i];
for (i = 0; str2[i] != '\0'; i++)
{
for (j = 0; chs[j] != '\0'; j++)
{
if (str[i] == chs[j])
{
str2[i] = rot13[j];
break;
}
}
}
for (i = 0; str2[i]; i++)
write(1, &str2[i], 1);
free(str2);
return (len);
}