我想這是要求最常見的錯誤之一,但在這種情況下,我知道它是與指針的使用:「錯誤:數組下標是不是一個整數」用C的指針
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.
如果有人能告訴我如何申報應該還是我怎麼能解決這個問題,我會很感激,也如果能稍微解釋一下我會很感激的答案。
Ps。對不起,英語不好,這不是我的自然語言,我也很感謝在寫作中的更正。
好問題。我認爲在將r1和r2轉換爲整數之前將其用於索引將有助於... –
「r1」和「r2」應該是「浮動」嗎?他們是否曾經需要一個非整數值(這與數組索引無關)? – Dmitri
對'r1','r2'和'col'使用'int'(或'size_t'或整數類型)。 – BLUEPIXY