我想这是最常见的错误之一,但在这种情况下,我知道它与指针的使用有关:
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.
如果有人能告诉我声明应该如何或如何解决这个问题,我将非常感激,如果能稍微解释一下答案,我将不胜感激。
附言。抱歉英语不好,这不是我的母语,我也希望在写作中得到更正。
最佳答案
您将 r1
和 col
声明为函数的 float
参数,因此当您尝试执行 M[r1][ col]
,你会收到错误“下标不是整数”,因为你的下标是float
,而不是整数。
关于c - C 中的 "Error: array subscript is not an integer"带指针,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40954202/