I've just write a code to free a multidimensional tab of float:
void matrix_destroy(float **that)
{
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 3; ++x) {
free (that[y][x]);
}
}
free (that);
}
And I got that error that I don't understand... :
SRC/creators_destructors.c: In function ‘matrix_destroy’: SRC/creators_destructors.c:56:10: error: incompatible type for argument 1 of ‘free’
free (that[y][x]);
^~~~ In file included from ./include/mylibs.h:13:0,
from SRC/creators_destructors.c:8: /usr/include/stdlib.h:448:13: note: expected ‘void *’ but argument is of type ‘float’ extern void free (void *__ptr) __THROW;
^~~~
# cc1 0.01 0.00
make: *** [<builtin>: SRC/creators_destructors.o] Error 1
If someone can help me
My code to it is as follow:
float **my_matrix;
if ((my_matrix = malloc(sizeof(float *) * 3)) == NULL)
perror("");
for (int i = 0; i < 3; ++i) {
if ((my_matrix[i] = malloc(sizeof(float) * 3)) == NULL)
perror("");
}
for (int y = 0; y < 3; ++y) {
for (int x = 0; x < 3; ++x) {
if (x == 0 && y == 0)
my_matrix[y][x] = 1;
else if (x == 1 && y == 1)
my_matrix[y][x] = 1;
else if (x == 2 && y == 2)
my_matrix[y][x] = 1;
else
my_matrix[y][x] = 0;
}
}
return (my_matrix);