-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memccpy.c
52 lines (45 loc) · 1.49 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
43
44
45
46
47
48
49
50
51
52
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memccpy.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpouget <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/14 17:04:37 by tpouget #+# #+# */
/* Updated: 2020/05/14 17:06:04 by tpouget ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memccpy(void *dest, const void *src, int c, size_t n)
{
size_t i;
unsigned char *d;
unsigned char *s;
unsigned char value;
i = 0;
d = (unsigned char*)dest;
s = (unsigned char*)src;
value = (unsigned char)c;
while (i < n)
{
d[i] = s[i];
if (s[i] == value)
break ;
i++;
}
return (i == n ? NULL : (dest + i + 1));
}
/*
#include <unistd.h>
int main(void)
{
char arr[] = "Hel12lo";
ft_memccpy(arr, "World", 'l', sizeof arr);
write(1, arr, sizeof arr);
write(1, "\n", 1);
ft_memccpy(arr, "World", 306, sizeof arr);
write(1, arr, sizeof arr);
write(1, "\n", 1);
return 0;
}
*/