Eorror : Invalid array access

 

MY source can't compile an Eorror : Invalid array access

 

my source

string split_line(string& output_array[] , string bufferline , string delimiter)
  {
     int s = ArraySize ( output_array );
     int l = StringLen( bufferline);
     int i,c,m,n;


     for(i =1 ; i<=s ; i++) { output_array[i-1]=""; }
     c=0;
     for(i=1 ; i<=l ; i++)
       {
           n = StringFind( bufferline , delimiter , i-1);
           if(n < 0 ) 
            {
               output_array[c] = StringSubstr(bufferline ,i-1, l-i+1);
               break;
            }
           output_array[c]= StringSubstr(bufferline , i-1 , n-i+1);
           i=n+1;
           c++;
           
       }   
       
     return( output_array );
  }

 

it eorror output_array hiw cab fix.


Help me please. 

 

It is very easy to find out yourself!

Just print out the relevant index of the array right before the array access and you would have got right away instead of waiting hours...

(Beside that you have three array accesses within a function how should we know how the array is defined (dynamic?) and where happens the error)

 
You're function is declared to return a single string, but you are trying to return an array (output_array) which can't be done.
Thus the compile error
Invalid access to an array (120) gooly, not the runtime ERR_ARRAY_INDEX_OUT_OF_RANGE (4002.)
string split_line(string& output_array[] , string bufferline , string delimiter)
  {
:
     return( output_array );
output_array is passed by reference and is the output. Don't try to return a value.
void split_line(string& output_array[] , string bufferline , string delimiter)
  {
:
     return;
Or return the count.
 
int split_line(string& output_array[] , string bufferline , string delimiter)
  {
:
     return c;
Or better yet, use the built in StringSplit - MQL4 Documentation
int split_line(string& output_array[] , string bufferline , string delimiter){
   return StringSplit(output_array, delimiter, bufferline);
}
Alphabetic Index of MQL4 Functions (600+) - MQL4 forum
Reason: