Homework 2, Arguing with the Arguments.

Short Description:

Write a program that parses command line arguments and behaves differently depending on the value given.

Goals

When you finish this homework, you should have:

Formal Description

This is a purely academic exercise. Please read the spec carefully to make sure your program performs correctly.

For reasons to be specified later write a c++ program called hw2.cpp (executable hw2). Make this program behave differently based on

  1. The command line arguments.
  2. The name used to invoke the program.
Your program should recognize and respond to the following command line arguments.

The output format should be each line starts with a tab, then the next value to print.


[bennett@mirkwood closed]$ hw2 --arg 8 --arg 7 --arg 8 1 2 3 4 5
The selected args are:
        2
        1
        2 

The output order should be

[bennett@mirkwood closed]$ hw2 --arg 0 --var HOME -a
The selected args are:
        hw2

The args are:
        --arg
        0
        --var
        HOME
        -a

The selected environment is:
        HOME=/home/bennett

Your program should examine argv[0] and determine how it should execute.

Remember, you can form a hard link by typing ln oldfile newfile. So you might want to ln hw5 myargs. However this is quite cumbersome, so this Makefile might help. When using this makefile, all indented lines start with a tab.

Notes

Extra Credit

Any of the following will lead to extra credit being awarded.

Required Files

A single tar file containing the source code and makefile for this program.

Submission

Submit the assignment to the D2L folder Homework 2 by the due date.