-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_memmove.c
More file actions
48 lines (43 loc) · 1.51 KB
/
Copy pathft_memmove.c
File metadata and controls
48 lines (43 loc) · 1.51 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memmove.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ypetruzz <marvin@42lausanne.ch> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2021/10/11 14:52:52 by ypetruzz #+# #+# */
/* Updated: 2021/10/11 14:56:52 by ypetruzz ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dest, const void *src, size_t n)
{
unsigned char *destcopy;
const unsigned char *srccopy;
destcopy = (unsigned char *)dest;
srccopy = (const unsigned char *)src;
if (dest == src)
return (dest);
if (srccopy < destcopy)
{
while (n != 0)
{
n--;
*(destcopy + n) = *(srccopy + n);
}
return (dest);
}
while (n != 0)
{
n--;
*destcopy++ = *srccopy++;
}
return (dest);
}
/*int main()
{
unsigned char d[] = "gvedgfefqezfzefe";
const unsigned char s[] = "salutest";
printf("%s\n", (char)memmove(d, s, 7));
printf("%s\n", (char)ft_memmove(d, s, 7));
}*/