getopt
useful link: https://www.gnu.org/software/libc/manual/html_node/Using-Getopt.html
it is from header file unistd.h
which must be included
int opterr
default is nonzero, when parse unknow options or miss argument, it would panic
set to zero to make your own behavior.
int optopt
use with opterr, get the option character
int optind
option character index which from 1 to start, end when option return -1
use with argc to check if non-option argument begin
char *optarg
option argument
int getopt
int main(int argc, char *argv[]){
int c;
while((c = getopt(argc, argv, "abc:")) != -1) {
switch(c) {
case 'a':
break;
//
}
}
}