Malloc Char **
Malloc Char ** Without ANY valgrind errorunknown
c_cpp
5 years ago
1.5 kB
4
Indexable
File Edit Options Buffers Tools C Help
/*
** EPITECH PROJECT, 2021
** test
** File description:
** test
*/
#include <stddef.h>
#include <stdlib.h>
#include "../includes/my.h"
void filled_array(char **array, int len)
{
for (int i = 0; i < len; i++) {
for (int c = 0; c < len; c++)
array[i][c] = '0' + i + c;
array[i][len] = '\0';
}
array[len] = NULL;
}
void display_array(char **array)
{
for (int i = 0; array[i] != NULL; i++) {
my_putstr(array[i]);
my_putchar('\n');
}
}
void free_array(char **array)
{
for (int i = 0; array[i] != NULL; i++)
free(array[i]);
free(array);
}
int main(void)
{
int len = 10;
char **array = malloc(sizeof(char *) * (len + 1));
for (int i = 0; i < len; i++)
array[i] = malloc(sizeof(char) * (len + 1));
filled_array(array, len);
display_array(array);
free_array(array);
return (0);
}Editor is loading...