-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprint_rot13.c
More file actions
51 lines (47 loc) · 1.13 KB
/
print_rot13.c
File metadata and controls
51 lines (47 loc) · 1.13 KB
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
44
45
46
47
48
49
50
51
#include "main.h"
/**
*print_rot13 - fun that print str in code rot13
**@pa: points to the list of arguments
*@pCount: pointer to counter
*Return: 0;
*/
int print_rot13(va_list pa, int *pCount)
{
char *str = va_arg(pa, char *);
int i, j;
char a[] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x',
'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J',
'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V',
'W', 'X', 'Y', 'Z'};
char b[] = {'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y',
'z', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
'l', 'm', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W',
'X', 'Y', 'Z', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
'J', 'K', 'L', 'M'};
if (str == NULL)
{
str = "(null)";
_putstr(str, _strlen(str));
*pCount += _strlen(str);
return (-1);
}
for (i = 0; str[i] != '\0'; i++)
{
for (j = 0; (a[j] != '\0' && str[i] != a[j]);)
{
j++;
}
if (str[i] == a[j])
{
_putchar(b[j]);
*pCount += 1;
}
else
{
_putchar(str[i]);
*pCount += 1;
}
}
return (0);
}