【问题标题】:C getopt from cmdline with more than two optionsC getopt from cmdline 有两个以上的选项
【发布时间】:2014-05-25 03:34:56
【问题描述】:

你知道 getopt() 函数。我用它成功地获得了两个选项,但我不知道如何获得三个选项。我该怎么做?

这是我如何获得其中两个:

while ((c = getopt(argc, argv, "al?:")) != -1){
        switch(c){
            case 'a' :
                hide_hidden_files = false; 

                break;
            case 'l' : 
                show_file_info = true;
                break;
            case '?' : 
                //error handling here
                return 1;
        }
    }

【问题讨论】:

  • 通过添加另一个选项和另一个开关盒。
  • 没想到答案这么简单。谢谢你:)
  • 下次先读the documentation
  • @OliCharlesworth:为什么不将其添加为 aswer,这样可以“关闭”?

标签: c command-line command-line-arguments getopt


【解决方案1】:

当您使用getopt(3) 时,您不能有一个名为? 的选项。 getopt(3) 使用字母 ? 来通知您有无法识别的选项字母。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-12-27
    • 2021-08-31
    • 2021-08-03
    • 1970-01-01
    • 1970-01-01
    • 2021-06-24
    • 1970-01-01
    相关资源
    最近更新 更多