【发布时间】:2021-02-01 13:52:34
【问题描述】:
我已经编写了以下代码,但我收到了这些错误和警告,我无法在此代码中解决这些错误和警告。
在函数'main'中:
[警告] 传递 'matrix_read' 的参数 1 从没有强制转换的指针生成整数
[注意] 预期为“int”,但参数的类型为“int (*)[(sizetype)(no_of_columns)]”
在函数“matrix_read”中:
[错误] 下标值既不是数组也不是指针也不是向量
#include <stdio.h>
int no_of_rows, no_of_columns;
int matrix_read(int read_input);
int main() {
int matrixA[no_of_rows][no_of_columns];
printf("Enter the number of rows:");
scanf("%d", &no_of_rows);
printf("Enter the number of columns:");
scanf("%d", &no_of_columns);
matrix_read(matrixA);
return 0;
}
//Function to read the value from the users
int matrix_read(int read_input){
int i,j;
for(i=0; i < no_of_rows; i++ ){
for(j=0; j < no_of_columns; j++){
printf("Enter the elemnts [%d][%d]: ", i+1, j+1);
scanf("%d", &read_input[i][j]);
}
}
} ```
【问题讨论】:
-
见this C reference website和this answer。阅读 C 编译器的文档,例如GCC
-
另请注意,您正在初始化
matrixA数组之前您知道no_of_rows和no_of_columns的值。你最终会得到一个大小为零的数组。 -
几个问题,第一个:
int matrixA[no_of_rows][no_of_columns];这里的维度值是多少? -
MatrixA是一个二维数组,但matrix_read(int read_input)中的read_input是一个int。您不能将数组分配给int。 -
谢谢,@AdrianMole 我已经解决了你提到的冲突,你能帮我解决问题吗?我仍然面临这个问题
标签: arrays c function pointers