|
| 1 | +# Command Line Arguments |
| 2 | +## Motivation |
| 3 | +Often specific details of the behaviour of a program cannot be configured at |
| 4 | +compile time. Instead, methods to configure a program a run time are needed. |
| 5 | + |
| 6 | +Lets for example look at the shell command `cp`, which creates a copy of a file. |
| 7 | +Specifying the name of the file to copy and the name of the copy to create in |
| 8 | +the C source file of the program `cp` would be terrible for its usability. |
| 9 | +Instead, `cp` allows to specify source and destination at runtime by calling it |
| 10 | +with command line arguments, e.g. `cp orignal_file copy_of_original_file`. |
| 11 | + |
| 12 | +In this task you will learn who to use command line arguments in your own C |
| 13 | +programs. |
| 14 | + |
| 15 | +## Task |
| 16 | +- Create the program `knights` |
| 17 | + - The source should be placed in `knights.c`. Replace its contents with your |
| 18 | + solution |
| 19 | + - A Makefile for this program is already provided |
| 20 | +- If `knights` is called with no arguments, it should print: "We are The Knights |
| 21 | + Who Say "Ni!". We demand a shrubbery. One that looks nice. And not to |
| 22 | + expensive." |
| 23 | +- If the application is called with one or more arguments, of which at least one |
| 24 | + is "shrubbery", it should print: "We are no longer The Knights Who Say "Ni!". |
| 25 | + We are now The Knights Who Say Ekki-Ekki-Ekki-Ekki-PTANG. Zoom-Boing. |
| 26 | + Z'nourrwringmm. Bring us another shrubbery. Slightly higher than the first one. |
| 27 | + Then you now must cut down the mightiest tree in the forest - with a herring!" |
| 28 | +- If the application is called with five or more arguments, of which at least |
| 29 | + five are "it", it should print: "Arrhhg!". This has priority over the |
| 30 | + "shrubbery"-case |
| 31 | +- If no of the cases above match, the command should behave as it was called |
| 32 | + with no arguments |
| 33 | +- The current source code in `knights.c` contains some useful hints |
0 commit comments