-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memmove.c
53 lines (49 loc) · 1.4 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
53
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yeparra- <marvin@42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/09/22 00:40:17 by yeparra- #+# #+# */
/* Updated: 2023/11/08 23:18:43 by yeparra- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *s, const void *ct, size_t n)
{
unsigned char *dst;
unsigned char *src;
size_t i;
dst = (unsigned char *)s;
src = (unsigned char *)ct;
i = 0;
if ((dst == src) || (n == 0))
{
return (dst);
}
if (dst > src)
{
while (n-- > 0)
dst[n] = src[n];
}
else
{
while (i < n)
{
dst[i] = src[i];
i++;
}
}
return (dst);
}
/*
int main()
{
char *str = "Hello, world";
char *src = str;
char *dst = src + 2;
ft_memmove(dst, src, 13);
printf("%s\n", str);
return(0);
}*/