argp

getopt usage with/without option

时间秒杀一切 提交于 2019-12-11 03:12:08
问题 I'm writing a simple code making use of *argv[] parameter. I'd like to know whether I can use getopt() function for the following intent. ./myprogram -a PATH ./myprogram PATH The program can either take merely PATH (e.g. /usr/tmp ) or take -a option in addition to PATH . Can getopt() be used for this state? If can, how? 回答1: The program can either take merely PATH (e.g. /usr/tmp ) or take option in addition to PATH . Can getopt() be used for this state? If can, how? Certainly. I'm not sure

What's the difference between argp and getopt?

柔情痞子 提交于 2019-12-08 16:05:08
问题 I think the title is self explanatory. I am making a program and I was wondering what I should use of the two and why. 回答1: argp may be more flexible / powerful / etc, but getopt is part of the POSIX standard. Thats a choice you've to make based on whether you expect your program to be portable. 回答2: From the Argp manual: Argp provides features unavailable in the more commonly used getopt interface. These features include automatically producing output in response to the ‘--help’ and ‘-