-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_memset.c
52 lines (45 loc) · 1.67 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: fcorvaro <fcorvaro@student.42roma.it> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/02/18 09:11:51 by fcorvaro #+# #+# */
/* Updated: 2023/04/18 15:54:58 by fcorvaro ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/*#include <stddef.h>*/
void *ft_memset(void *dest, int ch, size_t len)
{
unsigned char *ptr;
ptr = (unsigned char *)dest;
while (len > 0)
{
ptr [len - 1] = ch;
len--;
}
return (dest);
}
/*memset function writes len bytes of value ch (converted to an
unsigned char) to the string dest. This function returns it's
first argument. ptr means pointer to.
size_t is an unsigned data type defined by standards. Is used
to rappresent the size of an object, it must be >0.
type casting is a way to convert a variable from one data type to another
data type.
the code below is used to test the function
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char str[15];
strcpy(str, "daje Roma daje");
puts(str);
memset(str, 'a', 10);
puts(str);
return (0);
}
*/