-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memccpy.c
38 lines (35 loc) · 1.26 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ohachim <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2018/10/09 03:01:54 by ohachim #+# #+# */
/* Updated: 2018/10/19 20:26:34 by ohachim ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
unsigned char *dup1;
unsigned char *dup2;
size_t cn;
cn = 0;
dup1 = dst;
dup2 = (unsigned char*)src;
while (cn < n && *dup2 != (unsigned char)c)
{
*dup1 = *dup2;
dup1++;
dup2++;
cn++;
}
if (*dup2 == (unsigned char)c)
{
*dup1 = (unsigned char)c;
dup1++;
return (dup1);
}
return (NULL);
}