-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelp_functions.c
More file actions
76 lines (68 loc) · 1.37 KB
/
help_functions.c
File metadata and controls
76 lines (68 loc) · 1.37 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
#include "main.h"
#include <stdio.h>
/**
* _rev_string - Reverses a string
* @str: string to reverse
* Return: a pointer to a character
*/
char *_rev_string(char *str)
{
int str_len, head;
char tmp, *dest;
for (str_len = 0; str[str_len] != '\0'; str_len++)
{}
dest = malloc(sizeof(char) * str_len + 1);
if (dest == NULL)
return (NULL);
_memory_cpy(dest, str, str_len);
for (head = 0; head < str_len; head++, str_len--)
{
tmp = dest[str_len - 1];
dest[str_len - 1] = dest[head];
dest[head] = tmp;
}
return (dest);
}
/**
* _base_len - Calculates the length for a number
* @num: number for which length is to be calculated
* @base: base to be use in calculation
* Return: an integer representing length of a number
*/
unsigned int _base_len(unsigned int num, int base)
{
unsigned int i;
for (i = 0; num > 0; i++)
{
num = num / base;
}
return (i);
}
/**
* _write_base - write characters to the stdout
* @str: parse string
* Return: nothing(void)
*/
void _write_base(char *str)
{
int i;
for (i = 0; str[i] != '\0'; i++)
{
_write(str[i]);
}
}
/**
* _memory_cpy - copy memory area
* @dest: destination for copied memory
* @src: source to copy form
* @n: number of bytes to copy
* Return: a pointer to destination
*/
char *_memory_cpy(char *dest, char *src, unsigned int n)
{
unsigned int i;
for (i = 0; i < n; i++)
dest[i] = src[i];
dest[i] = '\0';
return (dest);
}