-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathft_memccpy.c
42 lines (38 loc) · 1.46 KB
/
ft_memccpy.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: adiaz-lo <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/11/13 12:19:59 by adiaz-lo #+# #+# */
/* Updated: 2020/01/13 12:56:25 by adiaz-lo ### ########.fr */
/* */
/* ************************************************************************** */
/*
** This function copies 'n' bytes from the memory of 'src' to the memory of
** 'dst'.
** It stops when a 'c' character is found.
** For further information, please check the Standard C Library function
** 'memccpy(void *dst, const void *src, int c, size_t n)'.
*/
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
char *source;
char *destiny;
size_t i;
source = (char *)src;
destiny = (char *)dst;
i = 0;
while (i < n)
{
destiny[i] = source[i];
if (source[i] == (char)c || destiny[i] == (char)c)
{
return (dst + (++i));
}
i++;
}
return (NULL);
}