FileReadArray - no data in the array

 

Hi,

I try to read a file with several MagicNumbers in order to write it to an array. Somehow there is no data in the array.

The file contains this line:

2011,2012,2052,2053,2058,2029,2030,2059,88,123771,123772,123773,123774,123775,123776,123777,123778,123779,123780,123781,123782,123783,123784,123785,123786,2063,2064,2065,2067,3169,3269,3369,115479,1208500,1208501,1208502,2208500,2208501,2208502

The file is stored in the file-folder of the terminal.

May someone give me a hint what is wrong with the code?

void Read_System()
  {
int arr[];
int file_handle=FileOpen("System.txt",FILE_READ|FILE_TXT,","); //comma delimiter
   if(file_handle!=INVALID_HANDLE)
     {
      //--- read all data from the file to the array
      FileReadArray(file_handle,arr);
      //--- receive the array size
      int size=ArraySize(arr);
      //--- print data from the array
      Print("Total data = ",size);
      FileClose(file_handle);
     }
        else
      Print("File open failed, error ",GetLastError());

for(int y=0;y<ArraySize(arr);y++) {
   Print(arr[y] );
   }

  }
 

Because FileReadArray() is to use with binary files.

Read the documentation please !

 

Hi,

Thanks. I was on the wrong filetype.


I worked out the following function:


string fnReadFileValue(string filename, int line=-1, int column=-1)
{
string str = "";
string sep = ",";
ushort u_sep = StringGetCharacter( sep, 0 );

int fp = FileOpen(filename,FILE_READ|FILE_TXT,","); //comma delimiter
if( fp != INVALID_HANDLE ) {

   FileSeek(fp, 0, SEEK_SET );
   while( !FileIsEnding(fp)) {
   
      str = FileReadString( fp, 0);
      string values[];
      StringSplit(str, u_sep, values );

  }
   FileClose( fp );
}
else
   Print("File open failed, error ",GetLastError());

return str;
}


to load the function:

extern string  InpDirectoryName="Exports";               // Export Folder
extern string  Magic_Numbers_file = "Magics.txt";        // File of Magic Nnumbers

string Read_MagicNumbers;

Read_MagicNumbers = fnReadFileValue(InpDirectoryName+"//"+Magic_Numbers_file, -1, -1 );


... works :-)