-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_bzero.c
43 lines (36 loc) · 931 Bytes
/
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
/*
* The bzero(): erases the data in the n bytes of the memory starting at
* the location pointed to by s, by writing zeros (bytes containing '\0')
* to that area.
* If (n) is zero, bzero() does nothing.
*/
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
void ft_bzero(void *dest, size_t len)
{
size_t i;
i = 0;
while (i < len)
{
((unsigned char *)dest)[i] = 0;
i++;
}
}
int main()
{
char ptr[50] = "Ghaiath$$$$$$$$$$$$$$$Abdoush";
printf("Befor appling the bzero: %s\n", ptr);
// replacing All chars after ptr[7] to 0
bzero(ptr+7, 1);
printf("After appling bzero: %s\n", ptr);
char ptr2[50] = "Ghaiath$$$$$$$$$$$$$$$Abdoush";
printf("Befor appling the memset: %s\n", ptr2);
// replacing All chars after ptr[7] to 0
memset(ptr2+7, 0, 1);
printf("After appling memset: %s\n", ptr2);
// So it is actually the same of memset() function but :
// int c = 0;
//
return EXIT_SUCCESS;
}