-
Notifications
You must be signed in to change notification settings - Fork 0
/
function1.c
57 lines (52 loc) · 1003 Bytes
/
function1.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
44
45
46
47
48
49
50
51
52
53
54
55
56
#include "main.h"
/**
* print_reversed - Calls a function to reverse and print a string
* @arg: Argument passed to the function
* Return: The amount of characters printed
*/
int print_reversed(va_list arg)
{
int len;
char *str;
char *ptr;
str = va_arg(arg, char *);
if (str == NULL)
return (-1);
ptr = rev_string(str);
if (ptr == NULL)
return (-1);
for (len = 0; ptr[len] != '\0'; len++)
_putchar(ptr[len]);
free(ptr);
return (len);
}
/**
* rot13 - Converts string to rot13
* @list: string to convert
* Return: converted string
*/
int rot13(va_list list)
{
int i;
int x;
char *str;
char s[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
char u[] = "NOPQRSTUVWXYZABCDEFGHIJKLMnopqrstuvwxyzabcdefghijklm";
str = va_arg(list, char *);
if (str == NULL)
return (-1);
for (i = 0; str[i] != '\0'; i++)
{
for (x = 0; x <= 52; x++)
{
if (str[i] == s[x])
{
_putchar(u[x]);
break;
}
}
if (x == 53)
_putchar(str[i]);
}
return (i);
}