I've got a program that needs to accept multiple command line arguments. I've gotten to a stage where I need to set it up to accept argument n, which specifies the max and min lengths of the string that will eventually be printed. Basically input could look like this:
-a -n7,7 -i // with -a and -i being other arguments
I'm fine with picking out arguments on their own, but I'm not sure how to pluck out those max and min values too. I've had a go (see below), but whenever I try and use variables minimum and maximum, I just get a run time error. Cheers guys.
int c;
while ((c = getopt(argc, argv, ":wpsaevin")) != -1) {
switch (c) {
case 'w': // pattern matches whole word
mode = WHOLE;
break;
case 'p': // pattern matches prefix
mode = PREFIX;
break;
case 'a': // pattern matches anywhere
mode = ANYWHERE;
break;
case 's': // pattern matches suffix
mode = SUFFIX;
break;
case 'e': // pattern matches anywhere
mode = EMBEDDED;
break;
case 'v': // reverse sense of match
reverse_match = true;
break;
case 'i': // ignore case of pattern
ignore_case = true;
break;
case 'n': //Specifies word length
length_spec = true;
cin >> minimum >> maximum;
if (minimum == 0 && maximum == 0) { //no word limit
length_spec = false;
} else if (maximum == 0) {
maximum = 100;
}
break;
}
}
argc -= optind;
argv += optind;