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();
TCHAR *token1;
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"
i havent used the winapi too much before, but there might be a way to use atoi with it or the c way which is: - '0'. you could go the c++ route and use <stringstream>
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 *.