我无法从主函数中调用多维数组函数。我的参数有什么问题吗?声明?变量? ETC
#include<stdio.h>
#include<string.h>
#define MAX_VAL 100
//Function declaration
int input_values(int Z[][k], int j, int k);
int main(void)
{
int A(int [ ][k], int, int);
int m, n;
char comm[100];
while(1){
printf("\n>>");
gets(comm);
if(strcmp(comm,"MAKE A")== 0)
input_values(A, j, k );
}
}
//make or overwrite matrix
int input_values(int Z[][k], int j, int k)
{
int row, col;
//DETERMINING THE SIZE OF MATRIX
do{
printf("Enter the number of rows: ");
scanf("%d", &row);
if(row>100)
printf("Size is out of bounds! Size must be less than or equal to 100\n");
}while(row>100);
do{
printf("Enter the number of columns: ");
scanf("%d", &col);
if(col>100)
printf("Size is out of bounds! Size must be less than or equal to 100\n");
}while(col>100);
//ENTERING THE VALUES OF MATRIX
for(j=0; j<row; j++)
for(k=0; k<col; k++){
printf("A[%d][%d] = ", j, k);
scanf("%d", &Z[j][k]);
}
return Z[][];
}
#include<stdio.h>
#include<string.h>
#define MAX_VAL 100
//Function declaration
int input_values(int Z[][k], int j, int k);
int main(void)
{
int A(int [ ][k], int, int);
int m, n;
char comm[100];
while(1){
printf("\n>>");
gets(comm);
if(strcmp(comm,"MAKE A")== 0)
input_values(A, j, k );
}
}
//make or overwrite matrix
int input_values(int Z[][k], int j, int k)
{
int row, col;
//DETERMINING THE SIZE OF MATRIX
do{
printf("Enter the number of rows: ");
scanf("%d", &row);
if(row>100)
printf("Size is out of bounds! Size must be less than or equal to 100\n");
}while(row>100);
do{
printf("Enter the number of columns: ");
scanf("%d", &col);
if(col>100)
printf("Size is out of bounds! Size must be less than or equal to 100\n");
}while(col>100);
//ENTERING THE VALUES OF MATRIX
for(j=0; j<row; j++)
for(k=0; k<col; k++){
printf("A[%d][%d] = ", j, k);
scanf("%d", &Z[j][k]);
}
return Z[][];
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
嗯,
int Z[][k]
在 C 中不是有效语法。不能作为声明,也不能作为参数。而且它肯定不是 C#。此外,int A(int [ ][k], int, int); 是函数的前向声明。它与 input_values 的第一个参数不匹配。
我猜你最终得到了
A
的这种表示法,因为它没有给出语法错误。这是因为 C 编译器只是忽略其中无效的k
。Well,
int Z[][k]
isn't valid syntax in C. Not as a declaration and not as a parameter. And it certainly isn't C#.Furthermore,
int A(int [ ][k], int, int);
is a forward declaration for a function. It is not a match for the 1st parameter of input_values.I'm guessing you ended up with this notation for
A
because it gives no syntax errors. That is because the C compiler just ignores the invalidk
in there.