-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_calloc.c
More file actions
46 lines (41 loc) · 1.4 KB
/
ft_calloc.c
File metadata and controls
46 lines (41 loc) · 1.4 KB
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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: lcosta-g <lcosta-g@student.42.fr> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/09 13:16:17 by lcosta-g #+# #+# */
/* Updated: 2024/10/26 11:49:09 by lcosta-g ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t nmemb, size_t size)
{
size_t m_size;
void *temp;
if (!nmemb || !size)
return (malloc(0));
m_size = nmemb * size;
if (m_size / size != nmemb)
return (NULL);
temp = malloc(m_size);
if (!temp)
return (NULL);
ft_bzero(temp, m_size);
return (temp);
}
/*
#include <stdio.h>
int main(void)
{
float *arr;
int i;
i = 0;
arr = (float *)ft_calloc(5, sizeof(float));
printf("Memória alocada e preenchida por zeros:\n");
while (i < 5)
printf("%f\n", arr[i++]);
return (0);
}
*/