0

I have a function that takes 1d and 2d arrays. 2d array has a length but it depends on the user's input.

int eval(char expression[],float* array[]);

I am calling this function in another function myfunction() like:

eval(array1,array2);

array1 is declared as global(at the beginning of the code, before all the function declerations and it has constant length). array 2 is declared in myfunction() as:

float array2[m][n];  //m and n are given in the input

I take an error like:

[Error] cannot convert 'float (*)[(part + 3)]' to 'float**' for argument '2' to 'int eval(char*, float**)

How can i fix this problem? I am trying to declare array2 in global but it also gives error that array length isn't a constant.

Sorry if i am wrong in terms of the context,i am a new member.

NoWay
  • 11
  • 1
  • 5
  • 3
    An array of arrays (e.g. `float array2[m][n]`) is not the same as an array of pointers (e.g. `float* array[]`). – Kevin May 08 '17 at 16:08
  • @EugeneSh. sorry i already call it like that, i wrote it wrong in the question, i edit it now – NoWay May 08 '17 at 16:09
  • @Kevin I thought they were similar, is this the problem? – NoWay May 08 '17 at 16:10
  • 3
    Change the prototype to `int eval(char expression[],int n, float (*array)[n]);` and call it `eval(array1, n, array2);`. – mch May 08 '17 at 16:10
  • 1
    They are similar in usage (syntax-wise) but are quite different in structure. I'm trying to find a suitable duplicate question. – Kevin May 08 '17 at 16:11
  • @mch now it says array does not declared in this scope – NoWay May 08 '17 at 16:14
  • @NoWay show some code: http://ideone.com/6QA5nr works. – mch May 08 '17 at 18:04

0 Answers0