-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memmove.c
More file actions
61 lines (56 loc) · 1.84 KB
/
ft_memmove.c
File metadata and controls
61 lines (56 loc) · 1.84 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: simarcha <simarcha@student.42barcel> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/01/09 16:50:16 by simarcha #+# #+# */
/* Updated: 2024/01/19 13:19:49 by simarcha ### ########.fr */
/* */
/* ************************************************************************** */
//#include <stdio.h>
//#include <string.h>
#include "libft.h"
//memmove is safe to use over memcpy when you have overlapping places in memory
//memcpy does not use a buffer
//memmove does use a buffer
void *ft_memmove(void *dst, const void *src, size_t n)
{
size_t i;
i = n;
if (src == dst)
return (dst);
if (dst > src)
{
while (i > 0)
{
((unsigned char *)dst)[i - 1] = ((unsigned char *)src)[i - 1];
i--;
}
}
else
{
i = 0;
while (i < n)
{
((unsigned char *)dst)[i] = ((unsigned char *)src)[i];
i++;
}
}
return (dst);
}
/*
int main()
{
char src[30] = "ABCDEFGHijklmnopqrstuvwxyz1234";
char dst[30] = "";// dst is only NULL characters
char sim_dst[30] = "";
printf("Before memmove => %s\n",dst);
memmove(dst, src, sizeof(char) * 30);
printf("After memmove => %s\n",dst);//now like src
printf("Before Simon's memmove => %s",sim_dst);
ft_memmove(dst, src, sizeof(char) * 30);
printf("\nAfter Simon's memmove => %s\n",dst);
return (0);
}*/