Hi!
I am trying to make a function, which transposes matrix. When declaring it, i get this error, which i mention in the title. Ive tried to find the solution myself, but i am quite new to C, so i don
t even understand what does this error mean. (I know what is pointer, but dont know how to fix the error.) please could anyone explain what causes this error? And please have a look at my code, i am afraid that this won
t be the only error. So if someone will find any obvious errors, please let me know.
Thanks.
#include <stdio.h>
#include <stdlib.h>
#define MAX_ROW 50
#define MAX_COL 50
int transp(int i, int j, int m, int n, int temp, int mat[i][j]);
int main(void)
{
int i, j, m, n, temp;
int mat[MAX_ROW][MAX_COL];
// variable dim is set to smaller value of defined
// maximal number of rows and columns
int dim = (MAX_ROW < MAX_COL)? MAX_ROW : MAX_COL;
// input of matrix dimension
do {
printf("input nuber of rows < %d :", dim);
scanf("%d", &m);
printf("input number of cols < %d:", dim);
scanf("%d", &n);
} while (m < 1 || m > dim || n < 1 || n > dim);
// input of elements
printf("\ninput of elements:\n");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
printf("input element [%d][%d] : ", i, j);
scanf("%d", &mat[i][j]);
}
}
// printing matrix before transposing
printf("\n\matrix before transposing:\n");
for (i = 0; i < m; i++) {
for (j = 0; j < n; j++) {
printf("%3d", mat[i][j]);
}
printf("\n");
}
// print after transposing
// number of rows becomes number of columns ...
printf("\nMatrix after transposing:\n");
for (i = 0; i < n; i++) {
for (j = 0; j < m; j++) {
[ICODE]printf("%3d", transp(i, j, m, n, temp, mat[i][j])); [/ICODE]// i get the error on this line
}
printf("\n");
}
} //end of main
/************function transp****************//////
int transp (int i, int j, int m, int n, int temp, int mat[i][j])
{
for ( i=0; i<m; ++i )
{
for ( j=i+1; j<n; ++j )
{
temp = mat[i][j];
mat[i][j] = mat[j][i];
mat[j][i] = temp;
return (mat[j][i]);
}
}