-
Notifications
You must be signed in to change notification settings - Fork 0
/
function2.c
77 lines (68 loc) · 1.38 KB
/
function2.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
#include <stdio.h>
#include "main.h"
/**
* rev_string - reverses a string in place
*
* @s: string to reverse
* Return: A pointer to a character
*/
char *rev_string(char *s)
{
int len;
int head;
char tmp;
char *dest;
for (len = 0; s[len] != '\0'; len++)
{}
dest = malloc(sizeof(char) * len + 1);
if (dest == NULL)
return (NULL);
_memcpy(dest, s, len);
for (head = 0; head < len; head++, len--)
{
tmp = dest[len - 1];
dest[len - 1] = dest[head];
dest[head] = tmp;
}
return (dest);
}
/**
* write_base - sends characters to be written on standard output
* @str: String to parse
*/
void write_base(char *str)
{
int i;
for (i = 0; str[i] != '\0'; i++)
_putchar(str[i]);
}
/**
* base_len - Calculates the length for an octal number
* @num: The number for which the length is being calculated
* @base: Base to be calculated by
* Return: An integer representing the 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);
}
/**
* _memcpy - copy memory area
* @dest: Destination for copying
* @src: Source to copy from
* @n: The number of bytes to copy
* Return: The _memcpy() function returns a pointer to dest.
*/
char *_memcpy(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);
}