這個函式不能使用大寫字母的短選項嗎?
看下面的代碼:
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <unistd.h>
#include <getopt.h>
static struct option long_options[] =
{
{"reqarg", required_argument, NULL, 'r'},
{"optarg", optional_argument, NULL, 'o'},
{"noarg1", required_argument, NULL, 'N'},
{"noarg", required_argument, NULL, 'n'},
{NULL, 0, NULL, 0},
};
int main(int argc, char *argv[])
{
int opt;
int digit_optind = 0;
int option_index = 0;
char *string = "A::b:c:N";
while((opt =getopt_long_only(argc,argv,string,long_options,&option_index))!= -1)
{
printf("opt = %c\t\t", opt);
printf("optarg = %s\t\t",optarg);
printf("optind = %d\t\t",optind);
printf("argv[optind] =%s\t\t", argv[optind]);
printf("option_index = %d\n",option_index);
}
}
在命令列中直接結果如下:
# ./t -r 324 -n 234 -N asdf
opt = r optarg = 324 optind = 3 argv[optind] =-n option_index = 0
./t: option '-n' is ambiguous
opt = ? optarg = (null) optind = 4 argv[optind] =234 option_index = 0
./t: unrecognized option '-N'
opt = ? optarg = (null) optind = 6 argv[optind] =asdf option_index = 0
為啥會有這兩個紅色字體的顯示?struct option long_options[] 中不能定義大寫字母的短選項值嗎?
uj5u.com熱心網友回復:
樓主的問題解決了嗎。能分享下嘛。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/250298.html
標籤:工具平臺和程序庫
下一篇:C語言 貪吃蛇郵箱控制臺報錯
