c - detecting no argument with getopt_long -
how detect user passed no arguments program getopt_long? detect user calling program no arguments checking argc, user calling program dash?
$ my_prog -
do need include option somehow in getopt statement?
while(ca = getopt_long(argc, argv, "abc:d:",...)
what function return?
you can use optind
variable determine such arguments:
the variable optind index of next element of argv[] vector processed. shall initialized 1 system, , getopt() shall update when finishes each element of argv[].
for example,
for(int = optind; < argc; i++) printf("unknown argument: %s\n", argv[i]);
you can after argument processing find out if there such unexpected arguments.
Comments
Post a Comment