/ Published in: C
Expand |
Embed | Plain Text
int parseCMD(int argc, char** argv) { /* variables for getopt*/ int c; int index; /* configs for cmd-args*/ int aflag = 0; int bflag = 0; char *cvalue = NULL; /* this is where the magic happens*/ opterr = 0; while ((c = getopt (argc, argv, "xbc:")) != -1) { switch (c) { case 'x': aflag = 1; break; case 'b': bflag = 1; break; case 'c': cvalue = optarg; break; case '?': if (optopt == 'c') { fprintf (stderr, "Option -%c requires an argument.\n", optopt); } else if (isprint (optopt)) { fprintf (stderr, "Unknown option `-%c'.\n", optopt); } else { fprintf (stderr, "Unknown option character `\\x%x'.\n", optopt); } return -1; default: abort (); } } /* check what was recognized */ aflag, bflag, cvalue); /* error if argument not found */ for (index = optind; index < argc; index++) { } return 0; }
You need to login to post a comment.
