Good day to all, there is a binary file in which a program written in C ++ Builder is written, and which I need to rewrite. Faced the problem of reading and writing an array.
Below is the C # code:
using (BinaryReader reader = new BinaryReader(File.Open(path, FileMode.Open))) { // ΠΏΠΎΠΊΠ° Π½Π΅ Π΄ΠΎΡΡΠΈΠ³Π½ΡΡ ΠΊΠΎΠ½Π΅Ρ ΡΠ°ΠΉΠ»Π° // ΡΡΠΈΡΡΠ²Π°Π΅ΠΌ ΠΊΠ°ΠΆΠ΄ΠΎΠ΅ Π·Π½Π°ΡΠ΅Π½ΠΈΠ΅ ΠΈΠ· ΡΠ°ΠΉΠ»Π° while (reader.PeekChar() > -1) { int nk = reader.ReadInt32(); int N_vn = reader.ReadInt32(); int N_vv = reader.ReadInt32(); float d_vn = reader.ReadSingle(); float d_vv = reader.ReadSingle(); double t_n = reader.ReadDouble(); double t_k = reader.ReadDouble(); float L = reader.ReadSingle(); float P = reader.ReadSingle(); float Pm = reader.ReadSingle(); float Pp = reader.ReadSingle(); float kal_n = reader.ReadSingle(); float kal_v = reader.ReadSingle(); float res_v = reader.ReadSingle(); // float frez = reader.ReadSingle(); ΠΌΠ°ΡΡΠΈΠ² // int irez = reader.ReadInt32(); ΠΌΠ°ΡΡΠΈΠ² } } But the structure code written in Builder
typedef struct { int nk; int N_vn,N_vv; float d_vn,d_vv; TDateTime t_n; TDateTime t_k; float L; float P,Pm,Pp; float kal_n,kal_v; float res_v; float frez[4]; int irez[4]; } str_pereval; Help please understand, thanks
float[] frezi = new float[4]; frezi[4] = reader.ReadSingle();float[] frezi = new float[4]; frezi[4] = reader.ReadSingle();getting exceptionAn unhandled exception of type 'System.IndexOutOfRangeException' occurred in binary.exe Additional information: ΠΠ½Π΄Π΅ΠΊΡ Π½Π°Ρ ΠΎΠ΄ΠΈΠ»ΡΡ Π²Π½Π΅ Π³ΡΠ°Π½ΠΈΡ ΠΌΠ°ΡΡΠΈΠ²Π°.- Ethernetsint i = 0;then in the cyclefrezi[i] = reader.ReadSingle(); i++;frezi[i] = reader.ReadSingle(); i++;but on the second pass of the cycle I get an offset, because the array should fill up immediately, do I have to put anotherforloopformy solution? - Ethernets