-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memmove.c
More file actions
61 lines (50 loc) · 1.74 KB
/
ft_memmove.c
File metadata and controls
61 lines (50 loc) · 1.74 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aantonie <aantonie@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/10/11 22:22:23 by aantonie #+# #+# */
/* Updated: 2023/10/19 12:14:09 by aantonie ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
// What does memmove do? -> copies len bytes from string src to string dst
// 1. sizeof(int) * 10 - the size of 1 int times 10(in general)
// 2. memmove() can handle overlapping destination and source blocks of memory
// 3. otherwise memcpy is better to use
void *ft_memmove(void *dst, const void *src, size_t len)
{
size_t t;
unsigned char *dest;
unsigned char *source;
dest = (unsigned char *)dst;
source = (unsigned char *)src;
t = len;
if (dst > src)
{
while (t > 0)
{
dest[t - 1] = source[t - 1];
t--;
}
}
else if (src > dst)
ft_memcpy(dst, src, len);
return (dst);
}
// #include <stdio.h>
// #include <string.h>
// int main()
// {
// int source[10]= {1,2,3,4,5,6,7,8,9,10};
// int destination[10];
// memmove(destination, source, sizeof(int) * 10);
// int i;
// i = 0;
// while (i < 10)
// {
// }
// return 0;
// }