Recently I had a request from an ADN partner troubleshooting a problem with reading values from a text file.
Assume we have a text file with following contents
Helloworld|Autodesk.
And, user would like to split string with pipe delimitation, so expected output would be
Helloworld and Autodesk.
#define wprintf acutPrintf void readFile() { const wchar_t textFile[] = _T("C:\\Temp\\TFile\\helloworld.txt"); FILE * pFile = NULL; wchar_t f1[20], f2[20]; f1[0] = '\0'; f2[0] = '\0'; if (_wfopen_s(&pFile, textFile, L"r") != 0 && pFile != NULL) { wprintf(L"failure opening file %s !\n", textFile); return; } /* %[^|] = store everything before '|' in place holder */ while (fwscanf(pFile, L"%[^|]|%s\n", f1, f2) != EOF) { wprintf(L"I have read f1 as : %s \n", f1); wprintf(L"I have read f2 as : %s \n", f2); } fclose(pFile); }
This gives garbage values in the placeholders, like shown in below pic
The root cause of this problem lies in the preprocess macro define
_CRT_STDIO_ISO_WIDE_SPECIFIERS =1in ObjectARXSDK 2018\inc\rxsdk_common.props
To tackle issue with Visual Studio 2015, AutoCAD made a workaround, it is not a case anymore unfortunately this define lies in SDK and causing some other issues like I stated above.
You can remove this define from your SDK to avoid unnecessary issues while dealing with strings.
Recent Comments