-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
61 lines (55 loc) · 1.7 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: tcakir-y <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/10 16:27:29 by tcakir-y #+# #+# */
/* Updated: 2024/10/18 16:13:00 by tcakir-y ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
void *dest;
size_t total_size;
total_size = nmemb * size;
if (size == 0 || nmemb == 0)
return (malloc(1));
dest = (void *)malloc(total_size);
if (dest == NULL)
return (NULL);
ft_bzero(dest, total_size);
return (dest);
}
//int main(void)
//{
// int *arr1;
// int *arr2;
// int n = 7;
// arr1 = (int*)calloc(n, sizeof(int));
// arr2 = (int*)ft_calloc(n, sizeof(int));
// if (arr1 == NULL)
// {
// printf("Memory allocation failed!\n");
// return (1);
// }
// if (arr2 == NULL)
// {
// printf("Memory allocation failed!\n");
// return (1);
// }
// for (int i = 0; i < n; i++)
// {
// printf("%d ", arr1[i]);// Output: 0 0 0 0 0
// }
// printf("\n");
// for (int i = 0; i < n; i++)
// {
// printf("%d ", arr2[i]);
// }
// free(arr1);
// free(arr2);
// return (0);
//}