简体   繁体   English

错误 - C 中的下标值既不是数组也不是指针也不是向量

[英]Error - Subscripted value is neither array nor pointer nor vector in C

I have written the below code but I am getting these errors and warnings which I am unable to resolve within this code.我已经编写了以下代码,但我收到了这些错误和警告,我无法在此代码中解决这些错误和警告。

In function 'main':在 function '主要':
[Warning] passing argument 1 of 'matrix_read' makes integer from pointer without a cast [警告] 传递 'matrix_read' 的参数 1 使 integer 从没有强制转换的指针
[Note] expected 'int' but argument is of type 'int (*)[(sizetype)(no_of_columns)]' [注意] 预期为“int”,但参数的类型为“int (*)[(sizetype)(no_of_columns)]”
In function 'matrix_read':在 function 'matrix_read' 中:
[Error] subscripted value is neither array nor pointer nor vector [错误] 下标值既不是数组也不是指针也不是向量

#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]);
                        
        }
    }
    
    
} ```
int matrix_read(void *read_input, size_t no_of_rows, size_t no_of_columns);

int main(void) 
{
    size_t no_of_rows, no_of_columns;
    
    printf("Enter the number of rows:");
    scanf("%zu", &no_of_rows);
    
    printf("Enter the number of columns:");
    scanf("%zu", &no_of_columns);

    int matrixA[no_of_rows][no_of_columns];
    
    matrix_read(matrixA, no_of_rows, no_of_columns);
    
    return 0;
}


//Function to read the value from the users

int matrix_read(void *read_input, size_t no_of_rows, size_t no_of_columns)
{    
    int (*array)[no_of_rows][no_of_columns] = read_input;
    size_t i,j;
    for(i=0; i < no_of_rows; i++ )
    {
        for(j=0; j < no_of_columns; j++)
        {
            
            printf("Enter the elemnts [%zu][%zu]: ", i+1, j+1);
            scanf("%d", &(*array)[i][j]);
        }
    }
    return 0;
}
#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++){
            
             int matrixA[i][j];
            
            printf("Enter the elemnts [%d][%d]: ", i+1, j+1);
            scanf("%d",&matrixA[i][j]);
                        
        }
    }
    
    
}

You forgot to mention your array in the function below the main.您忘记在主下方的 function 中提及您的阵列。 Function is trying to reach the array but it can not find it. Function 正在尝试访问阵列,但找不到它。 You must define it in the function so that it can reach it.您必须在 function 中定义它,以便它可以访问它。 This code is working fine and the only difference is这段代码工作正常,唯一的区别是

//int matrixA[i][j]; 
// . 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 错误:C中的下标值既不是数组也不是指针也不是矢量 - error: subscripted value is neither array nor pointer nor vector in C 下标的值既不是数组,也不是指针,也不是向量 - subscripted value is neither array nor pointer nor vector in c C程序中的下标值既不是数组也不是指针也不是向量 - Subscripted value is neither array nor pointer nor vector in C program C下标值既不是数组也不是指针也不是向量 - C subscripted value is neither array nor pointer nor vector C-下标值既不是数组,也不是指针,也不是向量 - C - subscripted value is neither array nor pointer nor vector 下标值既不是数组也不是指针也不是向量的错误 - Error with subscripted value being neither array nor pointer nor vector “错误:下标值既不是数组,也不是指针,也不是矢量”,但是为什么呢? - “error: subscripted value is neither array nor pointer nor vector”, but why? 错误:在 function 中打印数组时,下标值既不是数组也不是指针也不是向量(C) - error: subscripted value is neither array nor pointer nor vector when printing an array within a function (C) 下标值既不是数组也不是指针,也不是数组索引处的向量 - Subscripted value is neither array nor pointer nor vector at array index C:下标值既不是数组也不是指针 - C: Subscripted value is neither array nor Pointer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM