forked from MatiasAcostaDiaz/printf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstring_funcs.c
More file actions
100 lines (86 loc) · 1.6 KB
/
string_funcs.c
File metadata and controls
100 lines (86 loc) · 1.6 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
#include "holberton.h"
/**
* print_char - print a character
* @args: the argument passed
* Return: the count of element printed
*/
int print_char(va_list args)
{
char c = va_arg(args, int);
write(1, &c, 1);
return (1);
}
/**
* print_string - print an string
* @args: the argument passed
* Return: the count of element printed
*/
int print_string(va_list args)
{
char *s;
int n = 0;
s = va_arg(args, char *);
if (s == NULL)
{
s = "(null)";
}
n = _strlen(s);
write(1, s, n);
return (n);
}
/**
* print_percent - print a percent
* @args: argument passed
* Return: the count of element printed
*/
int print_percent(va_list args)
{
(void)args;
_putchar('%');
return (1);
}
/**
* print_reversed - print an string reversed
* @args: the argument passed
* Return: the count of element printed
*/
int print_reversed(va_list args)
{
char *string;
int length = 0, i = 0;
string = va_arg(args, char *);
length = _strlen(string);
for (i = length - 1; i >= 0; i--)
_putchar(string[i]);
return (length);
}
/**
* print_rot13 - print an string in rot13
* @args: argument passed
* Return: the count of element printed
*/
int print_rot13(va_list args)
{
int i = 0, j = 0;
char letras[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char root13[] = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";
char *string;
string = va_arg(args, char *);
if (string[0] == '\0')
return (0);
while (string[i])
{
for (j = 0; j <= 51; j++)
{
if (string[i] == letras[j])
{
_putchar(root13[j]);
break;
}
}
if (j > 51)
_putchar(string[i]);
i++;
}
return (i);
}