I have the following problem. The function printMatrix
Receive an matrix for example:
matrix:
[[0,1,1,2],
[0,5,0,0],
[2,0,3,3]]
The code that I must use is the following:
// Definition for arrays:
// typedef struct arr_##name {
// int size;
// type *arr;
// } arr_##name;
//
// arr_##name alloc_arr_##name(int len) {
// arr_##name a = {len, len > 0 ? malloc(sizeof(type) * len) : NULL};
// return a;
// }
//
//
void printMatrix(arr_arr_integer matrix)
{
}
As a clue they give me that the number of columns and rows can be determined in the following way.
int columns = matrix.arr->size; //No.columns
int rows = matrix.size; //No.rows
//Or
int columns = matrix.arr[0].size; //No.columns
int rows = matrix.size; //No.rows
My question lies in how is the rest of the code written so that the previous tracks can work?
That is, for this to work within the function printMatrix
What should you add or modify in your code for the above methods to work?
typedef struct arr_arr_integer {
int size;
type *arr;
} arr_arr_integer;
arr_arr_integer alloc_arr_arr_integer(int len) {
arr_arr_integer a = {len, len > 0 ? malloc(sizeof(type) * len) : NULL};
return a;
}
void printMatrix(arr_arr_integer matrix)
{
int columns = matrix.arr->size; //No.columns
int rows = matrix.size; //No.rows
//print matrix?
}
int main(int argc, char const *argv[])
{
//input matrix?
printMatrix(arr_arr_integer matrix)
return 0;
}
I repeat. I must use this code strictly
int columns = matrix.arr->size; //No.columns
int rows = matrix.size; //No.rows
The problem is that when I try to use those tracks I get the following compilation error.
error: request for member 'size' in something not a structure or union
See Question&Answers more detail:
os