Repository navigation
Expand file tree
/
Copy pathft_calloc.c
More file actions
72 lines (64 loc) · 2.03 KB
/
Copy pathft_calloc.c
File metadata and controls
72 lines (64 loc) · 2.03 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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/* ************************************************************************** */
/* */
/* /#/ |#/|#| */
/* ft_calloc.c /#/ |/ |#| */
/* /#/ /#/ */
/* By: nepcohen <nepcohen@learner.42.tech> /#/ /#/ */
/* /#/____ |#| /| */
/* Created: 2026/06/05 22:52:15 by nepcohen |#######| |#|/#| */
/* Updated: 2026/06/08 15:54:33 by nepcohen |#| NEPH_ */
/* */
/* ************************************************************************** */
#include <stdlib.h>
#include <stddef.h>
/* PROG ===================================================================== */
static void ft_bzero(void *s, size_t n)
{
unsigned char *c;
size_t i;
c = (unsigned char *)s;
i = 0;
while(i < n)
{
c[i] = 0;
i++;
}
}
void *ft_calloc(size_t n, size_t size)
{
void *result;
result = malloc(n * size);
if (result == NULL)
return (NULL);
ft_bzero(result, n * size);
return (result);
}
/* MAIN ===================================================================== */
#include <stdio.h>
int main(int argc, char **argv)
{
int *take;
size_t count;
take = ft_calloc(atoi(argv[1]), sizeof(int));
if (argc != 2)
{
printf("Merci de saisir les arguments du main `1`");
return (1);
}
else if (take == NULL)
return (1);
else
{
count = 0;
while (count < (size_t)atoi(argv[1]))
{
printf("return :`%d`\n", take[count]);
count++;
}
free(take);
}
return (0);
}
/* ========================================================================== */
/* END ====================================================================== */
/* ========================================================================== */