c - C 中的 "Error: array subscript is not an integer"带指针

标签 c arrays pointers

我想这是最常见的错误之一,但在这种情况下,我知道它与指针的使用有关:

float  *interpolar_renglon(float val,float col,float **M,float r1,float r2)
{  
    float *l=malloc(6*sizeof(float));  
    l[0]=interpolar(val, M[r1][col], M[r1][0], M[r2][col], M[r2][0]);  
    l[1]=interpolar(val, M[r1][col], M[r1][1], M[r2][col], M[r2][1]);  
    l[2]=interpolar(val, M[r1][col], M[r1][2], M[r2][col], M[r2][2]);  
    l[3]=interpolar(val, M[r1][col], M[r1][3], M[r2][col], M[r2][3]);  
    l[4]=interpolar(val, M[r1][col], M[r1][4], M[r2][col], M[r2][4]);  
    l[5]=interpolar(val, M[r1][col], M[r1][5], M[r2][col], M[r2][5]);  
    return (l);
}

这是我程序中的一个函数,它应该从数组 M 中获取一个特定的浮点值和两行 6 个数字,它获取这些值并将它们发送到另一个函数,该函数将它们返回到数组 l大小为 6。该函数将返回数组 l。

这里的问题是它向我发送了这个错误:

"Error: array subscript is not an integer" which I know is because the subscripts in the l array that should be of type int, but since this array was declared as a pointer I don't know how to solve this problem since I´m practically new to the pointers.

如果有人能告诉我声明应该如何或如何解决这个问题,我将非常感激,如果能稍微解释一下答案,我将不胜感激。

附言。抱歉英语不好,这不是我的母语,我也希望在写作中得到更正。

最佳答案

您将 r1col 声明为函数的 float 参数,因此当您尝试执行 M[r1][ col],你会收到错误“下标不是整数”,因为你的下标是float,而不是整数。

关于c - C 中的 "Error: array subscript is not an integer"带指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40954202/

相关文章:

c - 从C中的txt文件中读取整数

c - 以下简单代码的 O 效率是多少?如何?

java - java中将字符串转换为二维数组

c++ - 如何使用指针 C++ 将二维数组中的元素复制到一维数组中

c++ - 我应该将什么类型的指针传递给 C++11 中的方法?

c - 关于将指针作为参数传递

Linux 的 PHP 扩展 : reality check needed!

c - 将 awk 输出通过管道传输到 C 程序中

javascript - 如何在另一个对象数组中的备用位置添加对象?

Javascript 从数组中删除重复的对象