-
Notifications
You must be signed in to change notification settings - Fork 0
/
utils_3.c
60 lines (54 loc) · 866 Bytes
/
utils_3.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
#include "main.h"
/**
* _isprint - Tells if character is printable
* @c: character
* Return: 1 if printable, 0 if not
*/
int _isprint(char c)
{
if ((c > 0 && c < 32) || c >= 127)
return (0);
return (1);
}
/**
* rev_string - reverses string
* @s: string to reverse
*/
void rev_string(char *s)
{
int i, j;
char tmp;
for (i = 0; s[i]; i++)
;
j = 0;
while (--i > j)
{
tmp = s[i];
s[i] = s[j];
s[j] = tmp;
j++;
}
}
/**
* rot13 - does a rot13 on given string
* @s: string to rot13 onto
* Return: s
*/
char *rot13(char *s)
{
char alpha[] = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char alpharot[] = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";
int i, j;
for (i = 0; s[i]; i++)
{
for (j = 0; j < 52; j++)
{
if (s[i] == alpha[j])
{
s[i] = alpharot[j];
break;
}
}
}
return (s);
}