-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_helper_funcs.c
110 lines (95 loc) · 1.68 KB
/
_helper_funcs.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
105
106
107
108
109
110
#include "main.h"
/**
* _write - output chars to stdout
* @str: the str to loop over
*/
void _write(char *str)
{
int index = 0;
while (str[index] != '\0')
{
_putchar(str[index]);
index++;
}
}
/**
* oct_len - calculates the length for an octal number
* @num: number for which length is calculatet
* @base: base to calculate
* Return: int representing the length
*/
unsigned int oct_len(unsigned int num, int base)
{
unsigned int index = 0;
while (num > 0)
{
num = num / base;
index++;
}
return (index);
}
/**
* mem_cpy - copy memory area
* @dest: placeholder for copying
* @src: to copy from
* @num: No. of bytes to copy
* Return: pointer to dest
*/
char *mem_cpy(char *dest, char *src, unsigned int num)
{
unsigned int index = 0;
while (index < num)
{
dest[index] = src[index];
index++;
}
dest[index] = '\0';
return (dest);
}
/**
* rev_string - reverses a string in place
* @str: string to reverse
* Return: pointer to character
*/
char *rev_string(char *str)
{
int len, head;
char tmp;
char *dest;
for (len = 0; str[len] != '\0'; len++)
{}
dest = malloc(sizeof(char) * len + 1);
if (dest == NULL)
{
return (NULL);
}
mem_cpy(dest, str, len);
for (head = 0; head < len; head++, len--)
{
tmp = dest[len - 1];
dest[len - 1] = dest[head];
dest[head] = tmp;
}
return (dest);
}
/**
* hex_check - checks which hex function is calling it
* @num: number to convert
* @x: signals which hex function is calling it
* Return: the ASCII value for a letter
*/
int hex_check(int num, char x)
{
char *hex = "abcdef";
char *Hex = "ABCDEF";
num = num - 10;
if (x == 'x')
{
return (hex[num]);
}
else
{
return (Hex[num]);
}
return (0);
}