-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_memset.c
64 lines (52 loc) · 1.94 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
57
58
59
60
61
62
63
64
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_memset.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ledias-d <[email protected]> #+# +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024-10-11 12:56:28 by ledias-d #+# #+# */
/* Updated: 2024-10-11 12:56:28 by ledias-d ### ########.rio */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_memset(void *b, int c, size_t len)
{
unsigned char *temp_ptr;
temp_ptr = (unsigned char *)b;
while (len > 0)
{
*(temp_ptr++) = (unsigned char)c;
len--;
}
return (b);
}
/*#include <stdio.h>
#include <string.h>
void test_ft_memset(void *b, int c, size_t len, size_t size)
{
char original[size];
memcpy(original, b, size);
printf("Original: %s\n", (char *)b);
ft_memset(b, c, len);
printf("ft_memset: %s\n", (char *)b);
memset(original, c, len);
printf("memset: %s\n", original);
if (memcmp(b, original, size) == 0)
printf("Test Passed\n");
else
printf("Test Failed\n");
printf("--------------\n");
}
int main(void)
{
char buffer1[20] = "";
char buffer2[20] = "Test string...";
char buffer3[10] = "42School";
char buffer4[1] = "";
test_ft_memset(buffer1, 'A', 5, sizeof(buffer1));
test_ft_memset(buffer2, 'X', 4, sizeof(buffer2));
test_ft_memset(buffer3, 'Z', 9, sizeof(buffer3));
test_ft_memset(buffer4, 'B', 0, sizeof(buffer4));
return (0);
}*/