[英]How to get rid of this command-line argument error?
我用c ++編寫了一個程序,該程序應該使用幾個命令行參數,第一個參數是整數,其余三個參數是浮點數。 處理該部分的代碼如下所示:
_tmain(__in int argc, __in PZPWSTR argv)
{
USHORT X, Y, Z, ZR, XR; // Position of several axes
JOYSTICK_POSITION iReport; // The structure that holds the full position data
BYTE id=1; // ID of the target vjoy device (Default is 1)
UINT iInterface=1; // Default target vJoy device
BOOL ContinuousPOV=FALSE; // Continuous POV hat (or 4-direction POV Hat)
int count=0;
DOUBLE Xr, Yr, Zr;
// Get the ID of the target vJoy device
if (argc>1 && wcslen(argv[1]))
sscanf_s((char *)(argv[1]), "%d", &iInterface);
sscanf_s((char *)(argv[2]), "%d", &Xr);
sscanf_s((char *)(argv[3]), "%d", &Yr);
sscanf_s((char *)(argv[4]), "%d", &Zr);
_tprintf("Acquired: X %d\nY %d\nZ %d\n", Xr, Yr, Zr);
the rest of the code ...}
我的問題是,當我通過編寫代碼在命令行中調用程序時
name.exe 1 15 16 17
我得到Xr = 15,但Zr = 16,而Yr只是一些看似隨機的巨大負數。
我知道這可能是一些非常基本的錯誤,但是我一直無法找到原來的錯誤。 感謝您的任何建議。
您需要使用%lf
轉換來讀取雙精度型。 您當前使用的%d
僅用於int
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.