简体   繁体   English

赋值使 integer 从没有强制转换的指针 [-Wint-conversion] 在 C

[英]Assignment makes integer from pointer without a cast [-Wint-conversion] in C

I want to read data in a file into 2d array, but in (array[i][j] = #) line this problem occurs我想将文件中的数据读入二维数组,但在(array[i][j] = #)行中出现此问题

void readmatrix(int **array,FILE * f,int row,int col){
    for(int i=0 ;i<row ;i++){
        for(int j=0 ;j<col;j++){
            int* num = NULL;
            fscanf(f, "%d",num);
            array[i][j] =  &num ;
        }
    }
}

You are passing pointer of pointer of int to the function and saving address of pointer of num into array.您正在将 int 指针的指针传递给 function 并将 num 指针的地址保存到数组中。 Below will work just cast the array into (int *) before invoke your function.下面将在调用 function 之前将数组转换为 (int *)。

void readmatrix(int *array,FILE * f,int row,int col){
    for(int i = 0; i < row * col; i++){
        int num;
        fscanf(f, "%d", &num);
        *(array + i) =  num ;
    }
}

暂无
暂无

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

相关问题 赋值使指针从整数变成整数,而不进行强制转换[-Wint-conversion] - assignment makes integer from pointer without a cast [-Wint-conversion] 警告:赋值使 integer 从没有强制转换的指针 [-Wint-conversion] 在 C - warning: assignment makes integer from pointer without a cast [-Wint-conversion] in C 警告:赋值使指针从整数开始,而在C程序中没有强制转换[-Wint-conversion] - warning: assignment makes pointer from integer without a cast [-Wint-conversion] in C program 如何解决“赋值使指针从整数开始而无需强制转换[-Wint-conversion]”? UNIX程序 - How to fix “ assignment makes pointer from integer without a cast [-Wint-conversion]”? C unix program 从 &#39;char *&#39; 对 &#39;char&#39; 的赋值使指针从没有强制转换的整数 [-Wint-conversion] - assignment to ‘char’ from ‘char *’ makes integer from pointer without a cast [-Wint-conversion] 为什么这是“从‘int’到‘char *’的赋值使来自 integer 的指针没有转换 [-Wint-conversion]” - Why this is "assignment to ‘char *’ from ‘int’ makes pointer from integer without a cast [-Wint-conversion]" 警告:赋值使指针从整数变成整数,而不进行强制转换[-Wint-conversion] - Warning: assignment makes integer from pointer without a cast [-Wint-conversion] 警告:赋值使指针从整数开始而没有强制转换[-Wint-conversion] - warning: assignment makes pointer from integer without a cast [-Wint-conversion] 警告:赋值使指针来自 integer 没有强制转换 [-Wint-conversion] p = (i + 1) * 100; - warning: assignment makes pointer from integer without a cast [-Wint-conversion] p = (i + 1) * 100; 使用 function 指针,但得到警告使来自 integer 的指针没有强制转换 [-Wint-conversion] - Using function pointer, but got warning makes pointer from integer without a cast [-Wint-conversion]
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM