-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_bzero.c
96 lines (84 loc) · 2.3 KB
/
ft_bzero.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: aschenk <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/11/21 14:21:44 by aschenk #+# #+# */
/* Updated: 2023/11/24 19:18:46 by aschenk ### ########.fr */
/* */
/* ************************************************************************** */
/*
This function operates similarly to the memset() function, with the distinction
that it automatically writes the NUL character (ASCII: 0) without requiring you
to explicitly specify it. Notably, bzero() does not return any value.
*/
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
unsigned char *ptr;
ptr = (unsigned char *)s;
while (n > 0)
{
*ptr = 0;
ptr++;
n--;
}
}
/*
#include <stdio.h>
#include <string.h>
int main(void)
{
char chars[11] = "ABCDEFGHIJ";
char my_chars[11];
strcpy(my_chars, chars);
int bytes_to_zero = 4;
printf("========================\n");
printf("== TESTING FT_BZERO() ==\n");
printf("========================\n\n");
printf("Setting %d block(s) of memory to NUL:\n\n", bytes_to_zero);
printf("Lib bzero():\n");
int i = 0;
printf("Before: '");
while (i < 10)
{
printf("%c ", chars[i]);
i++;
}
printf("'\n");
bzero(chars + 5, bytes_to_zero * sizeof(char));
printf("After: '");
i = 0;
while (i < 10)
{
printf("%c ", chars[i]);
i++;
}
printf("'\n\n");
printf("My ft_bzero():\n");
i = 0;
printf("Before: '");
while (i < 10)
{
printf("%c ", my_chars[i]);
i++;
}
printf("'\n");
ft_bzero(my_chars + 5, bytes_to_zero * sizeof(char));
printf("After (space introduced): '");
i = 0;
while (i < 10)
{
printf("%c ", my_chars[i]);
i++;
}
printf("'\n\n");
if (strcmp(chars, my_chars) == 0)
printf("--> OK!\n\n");
else
printf("--> ERROR!\n\n");
return (0);
}
*/