开发者

Mandatory options with getopt_long() in C

开发者 https://www.devze.com 2023-02-03 15:56 出处:网络
With C/ C++, getopt_long() can be used to parse command line arguments. Is it possible to tell the function that some of the options are mandatory? For example, how can I tell getopt_long that the par

With C/ C++, getopt_long() can be used to parse command line arguments. Is it possible to tell the function that some of the options are mandatory? For example, how can I tell getopt_long that the parsing should give error if startServer is called without mentioning the port below?

./startServer -开发者_JAVA技巧port 80

Note: I am not talking of option arguments as mandatory but rather the options themselves.


getopt_long() is not part of the C language. It is a GNU invention which is available in some C implementations, but far from all.

The version of getopt_long() in glibc (used in most Linux distributions) does not allow you to specify that an option is mandatory. You'll have to check them explicitly after you're done parsing the command line.

0

精彩评论

暂无评论...
验证码 换一张
取 消