Failed to convert contents to argv [] to float [] [] in C

I am making a program in which I multiply matrices, but my big problem is converting from input to two arrays, which I will ultimately multiply. Below is my conversion code, including declaring arrays. (I removed the check that the input is 8 valid floats as I debugged it).

//declare the arrays float a[2][2]; float b[2][2]; float c[2][2]; int main (int argc, char *argv[]) { int i,j,k,l; i=0; l=4; // declare and initialize arrays for( j =0; j<2; j++) { for(k=0;k<2; k++) { a[j][k]=atof[argv[i]]; b[j][k]=atof[argv[l]]; i++; l++; } } ...... 

I get an error when using atof when compiling, which says: "the indexed value is neither an array nor a pointer" I was looking for an error, but did not understand what this means in my case.

+4
source share
4 answers

I think you want the following:

 a[j][k]=atof(argv[i]); 

Note that using () , not [] around argv[i] - atof is a function, not an array.

+4
source

atof is a function - you can call functions using () , not the subscript operator [] .

  a[j][k] = atof(argv[i]); 

I guess it was a typo - maybe change your font?

+2
source

Use

 atof(argv[i]) 

instead

 atof[argv[i]] 

Beware of the difference between [] and () .

+1
source

atof is a function, so you should use atof(argv[i]);

+1
source

Source: https://habr.com/ru/post/1342944/


All Articles