我传递一个矩阵的函数C.一个问题,还有就是我想创建功能:在传递函数矩阵(C)
void ins (int *matrix, int row, int column);
,但我注意到,相较于载体,矩阵给我一个错误。我如何将我的矩阵传递给一个函数?
EDIT - >存在的代码:
// 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");
}
}
多少是你的矩阵的diemensions?是1D还是2D? – 2012-07-11 08:34:33
可能的重复http://stackoverflow.com/questions/546860/passing-arrays-and-matrices-to-functions-as-pointers-and-pointers-to-pointers-in/11274267#11274267 – Ulterior 2012-07-11 08:40:43