-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_calloc.c
49 lines (43 loc) · 1.61 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: ana-lda- <[email protected]> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/04/13 17:54:07 by ana-lda- #+# #+# */
/* Updated: 2024/04/30 13:11:59 by ana-lda- ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
/** @brief aloca a memoria solicitada, calloc define a memoria alocada a zero.
@param nmemb numeor de elementos a serem alocados.
@param size tamanho os elementos.
@return ponteiro para a memoria alocada, o null se a solicitacao falhar.
*/
void *ft_calloc(size_t nmemb, size_t size)
{
void *ptr;
ptr = (void *)malloc(nmemb * size);
if (ptr == NULL)
return (NULL);
ft_bzero(ptr, nmemb * size);
return (ptr);
}
/*#include <stdio.h>
#include <stdlib.h>
int main(void)
{
printf("ft_calloc: %p\n", ft_calloc(0, 0));
printf("calloc: %p\n", calloc(0, 0));
char *str;
str = calloc(sizeof(char), 7);
str[0] = 'm';
str[1] = 'a';
str[2] = 'r';
str[3] = 'c';
str[4] = 'e';
str[5] = 'l';
str[6] = 'o';
printf("%s\n", str);
}*/