forked from bridiefranks/42-libft-with-comments
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_bzero.c
38 lines (36 loc) · 1.81 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_bzero.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: bfranks <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2022/03/03 18:16:05 by bfranks #+# #+# */
/* Updated: 2022/03/22 13:30:05 by bfranks ### ########.fr */
/* */
/* ************************************************************************** */
/* This function writes n bytes-worth of zeros into the string pointed to by s. If n = 0, bzero() does nothing
* (i.e. returns nothing).*/
#include "libft.h"
void ft_bzero(void *s, size_t n)
{
unsigned char *p;
/*have to use an unsigned char pointer rather than the provided void pointer, as we want to move along the string
* in 1 byte increments- hence char, which are 1 byte. Using a pointer of this type tells the counter i to move along
* by 1 byte. Also, you can't dereference a void pointer (see while loop).*/
size_t i;
/*size_t type for counter, as it represents the size of an object (string length) and is compared to n, which is of
* size_t type.*/
p = s;
/*sets unsigned char pointer p to point to the same string as void pointer s*/
i = 0;
while (i < n)
/* up until n...*/
{
p[i] = 0;
/*fill the string with zeros*/
i++;
}
return ;
/* don't return anything (void). Could also just not have return in there at all.*/
}