When we use fscanf_s method in Visual studio 2013 (C++ Console application), Os- Winsever2008 (64 bit), the file pointer reads the data one or 2 bytes in advance. Eg: While reading text file , the second line of the file is "Administartor", but the fscanf_s() returns the word as "dministrator". Please help me to correct this issue. The code is working fine with WIndows XP 32 bit using Visual studio 2008.
FILE* pFile;
pFile = NULL;
string strFile = "E:\\10_Products.lrf";
fopen_s(&pFile, strFile.c_str(), "r");
char szTemp[256];
string strTemp = "";
if (NULL != pFile)
{
while (!feof(pFile))
{
nRet = fscanf_s(pFile, "%s", szTemp);
if (EOF == nRet)
{
cout << "EOF detected";
}
}
return 0;
}
The format of 10_Products.lrf file is given below.
[OPERATOR_LEVEL]
Administrator