c
This is an old revision of the document!
getopt
#include <unistd.h> #include <stdio.h> #include <stdlib.h> int main (int argc, char** argv) { int o; int opt_a; char* opt_c; while ((o = getopt (argc, argv, "abc:")) != -1) { switch (o) { case 'a': opt_a = 1; printf("a=yes\n"); break; case 'c': opt_c = optarg; printf("c='%s'\n",opt_c); break; case '?': //fprintf(stderr, "Unknown option `-%c'.\n", optopt); exit(1); } } argc -= optind; argv += optind; // throw away option arguments }
c.1248378025.txt.gz · Last modified: 2009/07/23 12:40 by tkbletsc