-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memmove.c
53 lines (49 loc) · 1.87 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: rruiz-sa <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/09/16 17:42:35 by rruiz-sa #+# #+# */
/* Updated: 2022/10/13 20:08:42 by rruiz-sa ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memmove(void *dst, const void *src, size_t len)
{
char *str_dst;
char *str_src;
str_dst = (char *)dst;
str_src = (char *)src;
if (!dst && !src)
return (NULL);
if (str_dst < str_src)
ft_memcpy(dst, src, len);
else if (str_dst == str_src)
return ((void *)dst);
else
{
while (len > 0)
{
str_dst[len - 1] = str_src[len - 1];
len--;
}
}
return ((void *)str_dst);
}
/*
1- Check if the dst and src exist
2- Create new string with the value of dst and other with src
3- If dst < src, copy in dest the len of str with memcpy.
4- If dst and src are equal return dst
5- If not(dst < src) and not (dst = src) then
-Iterate from right to left of str copying src to dst
6- Return dst
[Description ft_memcpy]
1- Check if the dst and src exist
2- Create new string with the value of dst and other with src
3- Iterates until to the parameter passed by the function(len)
4- Every iteration copy the value of source inside destination
5- Return destination
*/