-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions2.c
75 lines (70 loc) · 1.01 KB
/
functions2.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
#include "shell.h"
/**
* _memmove - Copies a block of memory from source to destination.
* @dest: Pointer to the destination buffer.
* @src: Pointer to the source buffer.
* @n: Number of bytes to copy.
*/
void _memmove(char *dest, const char *src, size_t n)
{
if (dest > src)
{
dest += n - 1;
src += n - 1;
while (n > 0)
{
*dest = *src;
dest--;
src--;
n--;
}
}
else if (dest < src)
{
while (n > 0)
{
*dest = *src;
dest++;
src++;
n--;
}
}
}
/**
* _itoa - Converts an integer to a string.
* @num: The integer to be converted.
* Return: A pointer to the converted string.
*/
char *_itoa(int num)
{
static char str[12];
int i = 0, j = 0, k = 0, l = 0, m = 0;
if (num == 0)
{
str[0] = '0';
str[1] = '\0';
return (str);
}
if (num < 0)
{
l = 1;
num = -num;
}
m = num;
while (m != 0)
{
m /= 10;
i++;
}
j = i - 1 + l;
if (l == 1)
str[0] = '-';
for (; j >= l; j--)
{
k = num % 10;
str[j] = k + '0';
num /= 10;
}
str[i + l] = '\0';
return (str);
}