Homework 3:
Short Description:
This assignment is worth 10 points.
Goals
When you finish this homework, you should
- Have written a program that parses command line arguments.
Formal Description
Write a program that will produce a set of integers. Please call your program counter.
By default counter should print the numbers 1 through 10 on a line separated by spaces. There should be no space after the final number.
The program should respond to the following command line arguments.
- -h, --help: print a help message describing command line arguments.
- -b n, -bn, --bottom=n: set the low value to be the integer n.
- -t n, -tn, --top=n: set the high value to be the integer n.
- -l m,n -lm,n --limit=m,n: set the low value to be m and the high value to be n.
- -r, --reverse: print from high to low, not low to high
- -s n -sn, --step=n: increment (or decrement) by n, the default is 1. The step value is restricted to positive integers (no negatives or 0).
- -v, --verbose: parse command line arguments and print a summary of the values. (See below)
You should parse all command line arguments before taking any actions. Values can be replaced by subsequent arguments. For example
counter -l 1 -l2 --low=4
Should count from 4 to 10 producing the output
4 5 6 7 8 9 10
You should never print a value lower than the low value or higher than the high value.
You should always print the starting value (low for normal and high for reverse mode).
If settings conflict after all arguments are parsed, you should print a message explaining the error and exit. For example if the low value is greater than the high value, an error should be printed and no output produced. Please print all errors to cerr, not cout.
For verbose mode:
Submission
Email a copy of the C code to complete the final task to your instructor by class time. If your code consists of a single file, the source code will be sufficient, if the code is in multiple files, you should submit a tar file containing the source code and a make configuration file required to build the project.