-
Notifications
You must be signed in to change notification settings - Fork 0
/
ft_calloc.c
48 lines (42 loc) · 1.34 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
/* ************************************************************************** */
/* */
/* :::::::: */
/* ft_calloc.c :+: :+: */
/* +:+ */
/* By: arommers <arommers@student.codam.nl> +#+ */
/* +#+ */
/* Created: 2022/10/17 08:44:25 by arommers #+# #+# */
/* Updated: 2023/03/18 22:18:17 by adri ######## odam.nl */
/* */
/* ************************************************************************** */
#include "../include/libft.h"
void *ft_calloc(size_t count, size_t size)
{
void *ptr;
size_t i;
i = 0;
ptr = malloc (count * size);
if (ptr == NULL)
return (NULL);
while (i < (count * size))
{
(*(unsigned char *)(ptr + i)) = 0;
i++;
}
return (ptr);
}
/*void *ft_calloc(size_t count, size_t size);
int main(void)
{
char *str = ft_calloc (3, sizeof(int));
unsigned int i;
i = 0;
while (i < 12)
{
printf("%c", str[i]);
i++;
}
free (str);
return (0);
}
*/