-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memset.c
56 lines (51 loc) · 1.55 KB
/
ft_memset.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
53
54
55
56
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tpouget <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2020/05/14 17:04:37 by tpouget #+# #+# */
/* Updated: 2020/05/28 10:39:42 by tpouget ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *s, int c, size_t n)
{
unsigned char *p;
unsigned char value;
size_t i;
p = (unsigned char*)s;
value = (unsigned char)c;
i = 0;
while (i < n)
{
p[i] = value;
i++;
}
return (s);
}
/*
#include <unistd.h>
#include <string.h>
int main(void)
{
char arr[10];
ft_memset(arr, 48, 10);
write(1, arr, 10);
write(1, "\n", 1);
ft_memset(arr, 49, 5);
write(1, arr, 10);
write(1, "\n", 1);
ft_memset(arr, 306, 1); // 306 - 256 = 50 --> '2'
write(1, arr, 10);
write(1, "\n", 1);
memset(arr, 306, 1);
write(1, arr, 10);
write(1, "\n", 1);
ft_memset(((void*)0), 'a', 12);
write(1, arr, 10);
write(1, "\n", 1);
return 0;
}
*/