Hi, While reading the double value from the written text file, the memory get corrupetd.Here is the sample code and its output for the scenario. Can anyone help in this.
#include ;
#include "stdafx.h"
int main(int argc, char* argv[])
{
double dbleArray[][4] = { -315.00000255999998,0.00000000000000000,0.00000000000000000,-166.19238000000001,
-329.19238000000001,315.00000255999998,-329.19238000000001,-329.19238000000001,
0.00000000000000000,0.00000000000000000,320.00000000000000,-536.00000000000000,
0.00000000000000000,0.00000000000000000,0.00000000000000000,1.0000000000000000};
//Write the data to the file
FILE\* pFile = NULL;
pFile = \_wfopen(L"C:\\\\Temp\\\\InputVolumeDetails.txt", L"w");
if(pFile)
{
for(int nRow=0; nRow<4; nRow++)
{
for(int nCol=0; nCol<4; nCol++)
{
fwrite(&dbleArray\[nRow\]\[nCol\], sizeof(double), 1, pFile);
}
}
}
fclose(pFile);
//Read the data from the file
double dbleArray\_r\[4\]\[4\];
FILE\* pFile\_r = NULL;
pFile\_r = \_wfopen(L"C:\\\\Temp\\\\InputVolumeDetails.txt", L"r");
if(pFile\_r)
{
for(int nRow=0; nRow<4; nRow++)
{
for(int nCol=0; nCol<4; nCol++)
{
fread(&dbleArray\_r\[nRow\]\[nCol\], sizeof(double), 1, pFile\_r);
printf("%f\\n",dbleArray\_r\[nRow\]\[nCol\]);
}
}
}
fclose(pFile);
return 0;
}
The output for the above code is -315.000003 0.000000 0.000000 -92559631348757048000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000 -92559631349317831000000000000000000000000000000000000000000000.000000