-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memccpy.c
executable file
·39 lines (35 loc) · 1.34 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: mwilliam <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2016/11/07 18:32:42 by mwilliam #+# #+# */
/* Updated: 2016/12/02 21:06:11 by mwilliam ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*
** Copies n bytes from src to dst, stopping when c is found
*/
void *ft_memccpy(void *dst, const void *src, int c, size_t n)
{
unsigned char *dst2;
unsigned const char *src2;
unsigned char d;
size_t index;
dst2 = (unsigned char *)dst;
src2 = (unsigned const char *)src;
d = c + '\0';
index = 0;
while (n > 0)
{
dst2[index] = src2[index];
if (src2[index] == d)
return (dst2 + (index + 1));
n--;
index++;
}
return (NULL);
}