代码之家  ›  专栏  ›  技术社区  ›  James

是否可以在getopt\u长参数列表中向后移动?

  •  0
  • James  · 技术社区  · 16 年前

    我想根据是否存在特定的论据,将论据列表中的一个委派给以下人员:

    ./test --do-thing-1 --option-A=7 --common-option --option-B=2 # options C and D not valid
    ./test --do-thing-2 --option-C=9 --common-option --option-D=1 # options A and B not valid
    

    main() 处理所有公共选项,并决定调用几个函数中的哪一个来处理其余的函数。

    请注意,我不想限制顺序,以便公共选项只能首先出现。

    我的问题是如果我重置 optind getopt_long 通过将无效字符串传递给 strncmp -所以我想我不该和optind闹着玩。

    我有一个谷歌,找不到任何关于是否有可能跳转的参考资料 参数列表(我知道 getopt ),如果是,我该怎么做?

    我不想使用任何非标准库(语言是纯c,请不要用c++)

    1 回复  |  直到 16 年前
        1
  •  1
  •   James    16 年前

    我的问题是,我没有设置我的最后一排 static struct option long_options[] 如果将数组设置为零,则可以正确地修复错误。

    optind