I have two files, one called N.bin and the other called R.bin. After months of use, I only noticed that I have a bug. However, I thought this would cause a system crash. But at first he did not do this, and the second gave the correct result. Here is the code:
Please see line 19 for how I mistakenly switched from Nfile, not Rfile.
// Read file N
1 long world_features_lSize; 2 FILE* NFile; 3 double* N; 4 NFile=fopen("N.bin","r+b"); 5 6 fseek (NFile , 0 , SEEK_END); 7 lSize = ftell (NFile); 8 fseek (NFile , 0 , SEEK_SET); 9 N = (double*) malloc (sizeof(double)*lSize); 10 result = fread (N,1,lSize,NFile); 11 fclose(NFile); ////////////////// Read R 12 FILE* RFile; 13 double* R; 14 RFile=fopen("R.bin","r+b"); 15 fseek (RFile , 0 , SEEK_END); 16 lSize = ftell (RFile); 17 fseek (RFile , 0 , SEEK_SET); 18 R = (double*) malloc (sizeof(double)*lSize); 19 result = fread (R,1,lSize,NFile); 20 fclose(RFile);
Please help me why this code works!
Louis source share