Skip to content

Commit 7edd547

Browse files
committed
Adding the file 4-free_grid.c and updating holberton.h
1 parent a97499a commit 7edd547

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

0x0B-malloc_free/4-free_grid.c

+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
#include "holberton.h"
2+
#include <stdlib.h>
3+
4+
/**
5+
* free_grid - frees a 2 dimensional grid previously created with malloc
6+
* @grid: double pointer to the 2d array to be freed
7+
* @height: number of rows on the 2d array
8+
*
9+
* Return: void
10+
*/
11+
12+
void free_grid(int **grid, int height)
13+
{
14+
int i;
15+
16+
for (i = 0; i < height; i++)
17+
free(grid[i]);
18+
19+
free(grid);
20+
}

0x0B-malloc_free/holberton.h

+1
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ char *create_array(unsigned int, char);
66
char *_strdup(char*);
77
char *str_concat(char*, char*);
88
int **alloc_grid(int, int);
9+
void free_grid(int**, int);
910

1011
#endif

0 commit comments

Comments
 (0)