-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memmove.c
52 lines (48 loc) · 1.51 KB
/
ft_memmove.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rgerdzhi <[email protected] +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/06/27 18:17:09 by rgerdzhi #+# #+# */
/* Updated: 2024/07/08 17:49:58 by rgerdzhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
void *dest_ptr;
dest_ptr = dest;
if (!dest && !src)
return (dest);
if (dest == src)
return (dest);
if (dest > src)
{
while (n--)
{
((char *)dest)[n] = ((const char *)src)[n];
}
}
else
{
while (n--)
{
*(char *)dest++ = *(const char *)src++;
}
}
return (dest_ptr);
}
/*
int main ()
{
char dest[] = "Ra";
const char src[] = "Hello";
memmove(dest, src, 3);
printf("After memmove dest = %s, src = %s\n", dest, src);
ft_memmove(dest, src, 3);
printf("After ft_memmove dest = %s, src = %s\n", dest, src);
return(0);
}
*/