c - 指定给定的 Shortopt 可以接受可选参数 C

标签 c getopt command-line-arguments

如何指定短选项可以接受 getopt 中的可选参数。

据我所知,GNU 的 C 语言 getopt 库仅通过在给定选项后添加 : 来支持短选项的必需参数。

示例:

static const char* short_opts = "s:evlh";

如何指定 s 接受参数,但不需要它们?

我知道如何在 Ruby 中执行此操作,但我一直无法弄清楚如何在 C 中执行此操作 - 我已经多次查看了 getopt 的 GNU 文档,但无济于事。

最佳答案

来自documentation :

If an option character is followed by two colons (‘::’), its argument is optional; this is a GNU extension.

关于c - 指定给定的 Shortopt 可以接受可选参数 C,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17933286/

相关文章:

编译语言基础知识

python - 如何在 python 中使用 ctypes 重载 C 库的弱声明函数?

c - 当我在 Unix 下运行 C 程序时,如何将参数读取为选项?

Linux GNU getopt : ignore unknown optional arguments?

在c中捕获 "stdin redirected file location string"

java - 命令行参数导致 "main"线程中出现异常

ocr - 超立方体命令行模式下的文本 block 位置和大小检测

c++ - 混合 C C++ 代码时动态库中的链接问题

c - 尝试在 C 中创建基本数组实用程序

bash - 将多个参数传递给 shell 脚本并解析它们