0
我必须解析命令行参数并将某些字符转换为整数。在Win32 API中从命令行解析的字符未处理异常
我有以下代码:
TCHAR *token1;
token1 = strchr(cmd_line, L'+');
MessageBox(NULL, token1, _T("test"), NULL);
//char *str = "+10 frogs";
TCHAR *endptr =" ";
long n = strtol(token1 + 1, &endptr, 0);
if (!*endptr)
MessageBox(NULL, "No error", _T("test"), NULL);
else
MessageBox(NULL, "error", _T("test"), NULL);
当命令提示被发送的命令“WesOPC.exe 10 -regserver”,则消息框显示“10 -regserver”。
我需要将10存储为整数。因此,我使用了strtol,但显示了带有错误的消息框。
,当我试图调试它,在线看到的错误
long n = strtol(token1 + 1, &endptr, 0);
是
Unhandled exception at 0x0042d368 in WesOPC.exe: 0xC0000005: Access violation reading location 0x00000001.
'N' 应该是10