I'm wondering why the below code not writing correct data to file. If I change the buffer size to some greater amout this code works fine.
For the below code, if I try to read a file less than 500 bytes it works good, but for a bigger file simply I have to increase the buffer. What I'm missing in the reading loop?
const int iBuffSiz = 500;
char chBuffer[iBuffSiz];
memset(chBuffer, 0, sizeof(chBuffer));
CFile file;
CFile fileO;
if(file.Open(XML_FILE_NAME, CFile::modeRead | CFile::typeBinary) == FALSE)
{
return;
}
if(fileO.Open(XML_FILE_NAME_O, CFile::modeCreate | CFile::modeWrite | CFile::typeBinary) == FALSE)
{
return;
}
while(file.Read(chBuffer, iBuffSiz) > 0)
{
try{
UINT iCount = strlen(chBuffer);
fileO.Write(chBuffer, iCount);
}
catch (CFileException *exp)
{
TCHAR szCause[255];
exp->GetErrorMessage(szCause, 255);
}
}
//Closing file handle and socket after complete file send
file.Close();
fileO.Close();