FileReadArray() issue

 

I am trying to Read values from a file but  struggling for past few days (its the first time i am trying to read the file so pardon any mistakes )

I   cant figure out what i am  doing wrong here.

here is the simplified version of the code: 

Here i am trying to read the values from bin file

struct Value
  {
   double open;   
  };
 
          
void init()
  {
   Value array[];
 
   ResetLastError();
   int file_handle=FileOpen("Open.bin",FILE_READ|FILE_BIN);
   if(file_handle!=INVALID_HANDLE)
     {
       FileReadArray(file_handle,array);
       int size=ArraySize(array);
       for(int i=0;i<size;i++)
       Print("Data = ",array[i].open );
       Print("Size = ",size);
       FileClose(file_handle);
     }
   else
      Print("ERROR: ",GetLastError());
}

 the  Print("Data = ",array[i].open );  always print 0 through out the for loop.

and Print("Size = ",size);  always print  9337 where as the lines in the bin files are over 10000

Data in Both Bin and csv files is something like this :

37.007
37.503
37.878
37.503
37.128
36.258
36.875
37.25
37.503
39.882
41.502
:
:
:
:
:
:
:

 
Sagheer Asghar: Data in Both Bin and csv files is something like this :

37.007
37.503
37.878
37.503:

That is only text/CSV files. You can not type binary files.
 
William Roeder:
That is only text/CSV files. You can not type binary files.

Dang ..... i was actually worried about that 

 
William Roeder:
That is only text/CSV files. You can not type binary files.
Huh ?
 
Sagheer Asghar:

I am trying to Read values from a file but  struggling for past few days (its the first time i am trying to read the file so pardon any mistakes )

I   cant figure out what i am  doing wrong here.

here is the simplified version of the code: 

Here i am trying to read the values from bin file

 the  Print("Data = ",array[i].open );  always print 0 through out the for loop.

and Print("Size = ",size);  always print  9337 where as the lines in the bin files are over 10000

Data in Both Bin and csv files is something like this :

37.007
37.503
37.878
37.503
37.128
36.258
36.875
37.25
37.503
39.882
41.502
:
:
:
:
:
:
:

Can you provide the bin file to check ?
 
Alain Verleyen: Huh ?

binary

Can you read binary files as typed?

 
William Roeder:


Can you read binary files as typed?

If the data structure is known there is no problem to read it as typed, that's why FileReadArray() exists.

Maybe I misunderstand your point.

 
Alain Verleyen:

If the data structure is known there is no problem to read it as typed, that's why FileReadArray() exists.

Maybe I misunderstand your point.

What was shown in original post:

Data in Both Bin and csv files is something like this :

37.007
37.503
37.878
37.503
37.128
36.258
36.875
37.25
37.503
39.882
41.502

Is a text file. If it was a binary file it would look like my previous post.