[英]Reading command line arguments
我正在嘗試讀取如下所示的命令行參數
./程序-aB -v
但是我似乎無法理解如何讀取-aB命令。
我曾嘗試將aB放在我的交換機中,但沒有用。 這是我工作的代碼。
void processCommandSwitches(int argc, char *argv[], char **ppszFileWidgets, Simulation sim){
int i;
// Examine each of the command arguments other than the name of the program.
for (i = 1; i < argc; i++)
{
switch (argv[i][1])
{
case 'v':
sim->bVerbose = TRUE;
break;
case '?':
*ppszFileWidgets = argv[i];
break;
default:
*ppszFileWidgets = argv[i];
}
*ppszFileWidgets = argv[i];
}
與其打開第二個字符(僅適用於單個字母), strcmp(const char *lhs, const char *rhs)
嘗試使用strcmp(const char *lhs, const char *rhs)
,它返回0(等於),正數(在rhs之后的lhs)或負數(lhs)在rhs之前)?
例如:
#include <string.h>
// ....
for (int i = 1; i < argc; ++i) {
if (strcmp(argv[i], "-v") == 0) {
// ...
}
else if (strcmp(argv[i], "-aB") == 0) {
// ...
}
// ...
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.