-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memset.c
49 lines (44 loc) · 1.42 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: yuske <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/10/12 03:25:00 by yfurutat #+# #+# */
/* Updated: 2022/11/23 11:09:11 by yuske ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
//13L fewest casts
// void *ft_memset(void *str, int ch, size_t n)
// {
// char *str_caster;
// size_t i;
// i = 0;
// str_caster = (char *)str;
// if (!n)
// return (str_caster);
// while (i < n)
// {
// str_caster[i] = ch;
// i++;
// }
// return (str_caster);
// }
//13L
void *ft_memset(void *str, int ch, size_t n)
{
unsigned char *str_caster;
size_t i;
i = 0;
str_caster = (unsigned char *)str;
if (!n)
return (str_caster);
while (i < n)
{
str_caster[i] = (unsigned char)ch;
i++;
}
return (str_caster);
}