-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpointers.c
More file actions
39 lines (36 loc) · 1.07 KB
/
pointers.c
File metadata and controls
39 lines (36 loc) · 1.07 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
/*
Funções relacionadas com alocação de memória
*/
#include <stdio.h>
#include <stdlib.h>
/**
* malloc func with safety condition included
* @param _size amount of memory to alloc
* @return pointer to the memory allocated or end of
* the program if an error happens
*/
void *safeMalloc(size_t _size){
void *p = malloc(_size);
if (p == NULL){
exit (0);
}
return p;
}
/**
* agglomerated of free funcs used dispite which program variant is called
* @param _num_tur_points num of points in tur_points array
* @param tur_points coordinates of each step of a path
* @param _height map numb of lines
* @param _num_tur_points number of points in the coordinates matrix
*/
void freeAll(unsigned int _num_tur_points, unsigned int ***tur_points,
unsigned int _height, unsigned char ***map){
for (int point_ix = 0; point_ix < _num_tur_points; point_ix++)
free((*tur_points)[point_ix]);
free(*tur_points);
*tur_points = NULL;
for (int row = 0; row < _height; row++)
free((*map)[row]);
free(*map);
*map = NULL;
}