【发布时间】:2010-09-18 08:54:02
【问题描述】:
我想在指针的帮助下扫描一个二维数组并编写了这段代码,你能告诉我为什么编译器会出错吗?我知道如何使用双指针来做同样的事情,我正在试验这个。
#include<stdio.h>
#include<stdlib.h>
int main(void) {
int i,j,n,a,b;
int (*(*p)[])[];
printf("\n\tEnter the size of the matrix in the form aXb\t\n");
scanf("%dX%d",&a,&b);
p=(int (*(*p)[b])[a])malloc(b*sizeof(int (*p)[a]));
for(i=0;i<b;i++) {
p[i]=(int (*p)[a])malloc(a*sizeof(int));
printf("\t\bEnter Column %d\t\n");
for(j=0;j<a;j++)
scanf("%d",&p[i][j]);
}
return 0;
}
【问题讨论】:
-
它可以帮助列出编译器错误,你知道的。 ;-)
-
“这个”是什么意思?构造 (int (*(*p)[b])[a]) ??那该怎么办?我的 gcc 似乎不喜欢那样。
-
determinant.c:9: error: expected ')' before 'p'determinant.c:9: error: expected ')' before '[' tokendeterminant.c:9: error: expected ')' 在 '[' 令牌确定性.c:9 之前:错误:预期';' 在'malloc'确定性.c:11 之前:错误:无效使用未指定边界的数组确定性.c:11:错误:预期') '在'p'之前determinant.c:11:错误:预期')'在'['令牌determinant.c:11之前:错误:无效使用未指定边界的数组determinant.c:11:错误:预期';'之前“malloc”determinant.c:14:错误:无效使用未指定边界的数组
标签: c pointers multidimensional-array