-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathft_calloc.c
53 lines (42 loc) · 1.53 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: anamart3 <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2023/04/02 13:09:22 by anamart3 #+# #+# */
/* Updated: 2023/04/23 16:11:50 by anamart3 ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t count, size_t size)
{
void *ptr;
if (count && ((SIZE_MAX / count) < size))
return (NULL);
ptr = malloc(count * size);
if (ptr == NULL)
return (NULL);
ft_bzero(ptr, count * size);
return (ptr);
}
// int main(void)
// {
// int i;
// int n;
// int *a;
// printf("Number of elements to be entered:");
// scanf("%d",&n);
// a = (int *)ft_calloc(n, sizeof(int));
// printf("Enter %d numbers:\n",n);
// for( i=0 ; i < n ; i++ ) {
// scanf("%d",&a[i]);
// }
// printf("The numbers entered are: ");
// for( i=0 ; i < n ; i++ ) {
// printf("%d ",a[i]);
// }
// free( a );
// return (0);
// }