-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstring_functions.c
98 lines (82 loc) · 1.44 KB
/
string_functions.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
#include "main.h"
/**
* _strlen - finds the length of a string
*
* @str: the string whose length is to be found
* Return: the length of the string.
*/
int _strlen(const char *str)
{
int i = 0;
while (*(str + i))
i++;
return (i);
}
/**
* reverse_string - reverses a string
*
* @str: the string to be reversed.
* Return: a pointer to the reversed string.
*/
char *reverse_string(char *str)
{
char *t = str;
char n[1024];
short c = 0;
while (*str != '\0')
{
n[c] = *str;
str++;
c++;
}
c = 0;
while (str > t)
{
str--;
*str = n[c];
c++;
}
return (str);
}
/**
* _strcpy - copies a string
*
* @dest: destination (the new copy of string src)
* @src: source (the string to be copied)
* Return: pointer to the copy of src string
*/
char *_strcpy(char *dest, const char *src)
{
int i;
for (i = 0; *(src + i) != '\0'; i++)
{
*(dest + i) = *(src + i);
}
dest[i] = '\0';
return (dest);
}
/**
* rot13 - rotates characters of a string by 13 places.
* It encrypts a string a string using the ROT-13 cypher.
*
* @str: the string to be encrypted.
* Return: encrypted string.
*/
char *rot13(char *str)
{
int i, j;
char *a = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";
char *b = "nopqrstuvwxyzabcdefghijklmNOPQRSTUVWXYZABCDEFGHIJKLM";
for (i = 0; *(str + i); i++)
{
for (j = 0; j < 52; j++)
{
if (*(a + j) == *(str + i))
{
*(str + i) = *(b + j);
break;
}
}
}
return (str);
}