Passing a matrix in a function (C)
c, matrix
Solution
You need to pass a pointer with as much levels of indirection (`*`) as the number of dimensions of your matrix.
For example, if your matrix is 2D (e.g. 10 by 100), then:
void ins (int **matrix, int row, int column);
If you have a fixed dimension (e.g. 100), you can also do:
void ins (int (*matrix)[100], int row, int column);
or in your case:
void ins (int (*matrix)[SIZE], int row, int column);
If both your dimensions are fixed:
void ins (int matrix[10][100], int row, int column);
or in your case:
void ins (int matrix[SIZE][SIZE], int row, int column);
Problem
I have an issue passing a matrix to a function in C. There is the function I want to create: ``` void ins (int *matrix, int row, int column); ``` but I noticed that in contrast to the vectors, matrix give me an error. How can I pass my matrix to a function so? EDIT --> there is the code: ``` // Matrix #include <stdio.h> #define SIZE 100 void ins (int *matrix, int row, int column); void print (int *matrix, int row, int column); int main () { int mat[SIZE][SIZE]; int row, col; printf("Input rows: "); scanf ("%d", &row); printf("Input columns: "); scanf ("%d", &col); printf ("Input data: \n"); ins(mat, row, col); printf ("You entered: "); print(mat, row, col); return 0; } void ins (int *matrix, int row, int column); { int i, j; for (i = 0; i < row; i++) { for (j = 0; j < column; j++) { printf ("Row %d column %d: ", i+1, j+1); scanf ("%d", &matrix[i][j]); } } } void print (int *matrix, int row, int column) { int i; int j; for(i=0; i<row; i++) { for(j=0; j<column; j++) { printf("%d ", matrix[i][j]); } printf("\n"); } } ```