-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memccpy.c
39 lines (36 loc) · 1.33 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jamrabhi <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2019/10/11 18:43:51 by jamrabhi #+# #+# */
/* Updated: 2021/06/05 19:46:21 by jamrabhi ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
size_t i;
unsigned char *str_dst;
unsigned char *str_src;
unsigned char ch;
i = 0;
str_dst = (unsigned char *)dst;
str_src = (unsigned char *)src;
ch = (unsigned char)c;
if (dst == NULL && src == NULL)
return (NULL);
while (i < n)
{
str_dst[i] = str_src[i];
i++;
if (str_src[i] == ch)
{
str_dst[i] = str_src[i];
return (dst + i + 1);
}
}
return (NULL);
}