8.3.0.10

B — The Very Basics

Due Monday, 13 September 2021, 11:59pm

Purpose to explore the most rudimentary properties of the chosen programming language; to deliver software as specified; and to learn to pair-program with your partner.

Delivery Deposit xhead in a directory called B in your repository (master branch). Put all auxiliary files into a sub-directory called Other.

You must be able to run this program at the shell command prompt as ./xhead. Our test harness will run the program as a sub-process, meaning your shell environment does not exist. In our experience, it is best to deliver a shell script that invokes your program, a compiled executable or an interpreted file.

Task Develop xhead, a program that re-directs a command-line-specified number of lines from STDIN to STDOUT. If the given number is larger than the total number of lines from STDIN, then all of STDIN is printed to STDOUT.

The natural number is specified on the command-line of the program prefixed with a dash. If the required command-line argument is missing or malformed, the program prints the word "error" (with quotes) to STDOUT. The program also prints the error message if the command-line contains extraneous material.

Example Run

    $ ls -l / | ./xhead -11

              ^

              |

              +-------------------- this is the pipe symbol (google "Unix pipe")

at the prompt of a terminal on your Delivery platform. The part to the left of the pipe symbol lists the files and directories at the root of the file system and the part to the right displays the first 11 lines on STDOUT.

(Yes, head exists on *nix OSes. That’s not the point.)