개요
- calloc이란? 메모리 할당에 쓰는 함수.
- malloc과는 다르게 메모리 공간을 그 크기만큼 0으로 초기화
- 기존에 사용한 함수; ft_bzero를 응용하면 좀 더 쉽게 할 수 있다.
코드
c
#include "libft.h"
void *ft_calloc(size_t count, size_t size)
{
void *arr;
arr = (void *)malloc(count * size);
if (!arr)
return (NULL);
ft_bzero(arr, count * size);
return (arr);
}