-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
43 lines (38 loc) · 1.27 KB
/
ft_calloc.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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: rhiguita <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/05/05 08:19:09 by rhiguita #+# #+# */
/* Updated: 2024/05/15 22:41:46 by rhiguita ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
size_t num_bytes;
num_bytes = nmemb * size;
ptr = malloc(num_bytes);
if (!ptr)
return (NULL);
ft_bzero(ptr, num_bytes);
return (ptr);
}
/*
int main()
{
size_t a = 5;
size_t b = sizeof(int);
int *ab = (int *)ft_calloc(a, b);
int i;
i = 0;
while (i < 5)
{
printf("ab[%i]=%d\n", i, *ab);
i++;
}
return (0);
}*/