【发布时间】:2009-09-16 07:31:58
【问题描述】:
为什么下面的代码给我一个分段错误?
#define MAXROWS 10
#define MAXCOLS 10
void getInput (int *data[MAXROWS][MAXCOLS]) {
int rows, cols;
int curRow, curCol;
printf ("How many rows and cols?");
scanf ("%d %d", rows, cols);
for (curRow = 0; curRow < rows; curRow++) {
for (curCol = 0; curCol < cols; curCol++) {
scanf ("%d", data[curRow][curCol]);
printf ("%d\n", *data[curRow][curCol]);
}
}
}
void main () {
int data[MAXROWS][MAXCOLS];
getInput (data);
}
似乎scanf 和printf 语句没有传入正确的数据类型,但我不知道它们应该是什么。
如何更改它以使其正常工作?
【问题讨论】:
-
什么时候出现段错误?
-
当它开始将值读入 data