-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_print_chars.c
104 lines (90 loc) · 1.65 KB
/
_print_chars.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
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
101
102
103
104
#include "main.h"
/**
* char_spesi - fuction to print a char
* @ap: arguement pointer
* @count: number of char printed
*/
void char_spesi(va_list ap, int *count)
{
_putchar(va_arg(ap, int));
(*count)++;
}
/**
* str_spesi - fuction to print a string
* @ap: arguement pointer
* @count: number of char printed
*/
void str_spesi(va_list ap, int *count)
{
int i;
char *ptr = va_arg(ap, char *);
if (!ptr)
ptr = "(null)";
for (i = 0; ptr[i]; i++, (*count)++)
_putchar(ptr[i]);
}
/**
* rev_spesi - function to reverse a string
* @ap: arguement pointer
* @count: number of char printed
*/
void rev_spesi(va_list ap, int *count)
{
char *ptr = va_arg(ap, char *);
rev(ptr, count);
}
/**
* rev - sub-function to reverse a string
* @str: string
* @count: number of char
*/
void rev(char *str, int *count)
{
int i;
for (i = 0; str[i]; i++)
;
i--;
while (*(str + 1))
str++;
for (; i >= 0; i--, (*count)++)
{
_putchar(*(str));
str--;
}
}
/**
* rot13_spesi - function that gives out the rotted output of a string
* @ap: arguement pointer
* @count: number of char printed
*/
void rot13_spesi(va_list ap, int *count)
{
int i, j;
char alpha_ptr[] = "ABCDEFGHIJKLMnopqrstuvwxyz";
char rot13_ptr[] = "NOPQRSTUVWXYZabcdefghijklm";
char *ptr;
ptr = va_arg(ap, char *);
for (i = 0; ptr[i]; i++, (*count)++)
{
j = 0;
if ((ptr[i] > 64 && ptr[i] < 91) || (ptr[i] > 96 && ptr[i] < 123))
{
while (alpha_ptr[j])
{
if (ptr[i] == alpha_ptr[j])
{
_putchar(rot13_ptr[j]);
break;
}
else if (ptr[i] == rot13_ptr[j])
{
_putchar(alpha_ptr[j]);
break;
}
j++;
}
}
else
_putchar(ptr[i]);
}
}