I have to parse the command enter in the command line argument and convert certain parameter of them into integer variable.
I can parse them but cannot convert them into integer . I have to convert the digits after '+' sign to integer variable.
The error is displayed as "Debug Assertion Error".
I am using Win32 API and code is as below:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
int WINAPI WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nShowCmd)
TCHAR *cmd_line = GetCommandLine();
token1 = strchr(cmd_line, L'+');
MessageBox(NULL, token1, _T("test"), NULL);
int i, value=0;
for ( i = 0; token1[ i ] != '\0'; ++i )
int digit = token1 [ i ] - '0';// get value of current digit character
value = 10 * value + digit;
It can build sucessfully but when i run it , it shows "Debug Assertion Error"
If you are compiling in Visual Studio, the above code is likely mixing types. TCHAR is defined as WCHAR if UNICODE or _UNICODE is defined, which are usually defined by default in visual studio projects. So your cmd_line variable is likely of type WCHAR *. You can't pass a WCHAR * to strchr which expects a CHAR *.