-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathft_calloc.c
More file actions
40 lines (37 loc) · 1.28 KB
/
ft_calloc.c
File metadata and controls
40 lines (37 loc) · 1.28 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
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ft_calloc.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: sudaniel <sudaniel@student.42heilbronn.de +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2024/10/10 14:37:36 by sudaniel #+# #+# */
/* Updated: 2024/10/10 15:57:52 by sudaniel ### ########.fr */
/* */
/* ************************************************************************** */
#include "libft.h"
void *ft_calloc(size_t count, size_t size)
{
unsigned char *p;
size_t new_size;
size_t index;
index = 0;
new_size = count * size;
p = (unsigned char *)malloc(new_size);
if (!p)
return (NULL);
while (new_size--)
p[index++] = 0;
return ((void *)p);
}
/*
int main(void)
{
char *s = ft_calloc(5, 1);
int i = 0;
while (i < 5)
s[i++] = 'a';
printf("%s\n", s);
return (0);
}
*/