Lab 1

Store all of your files for this lab in a folder named "lab1".

In this lab you will create filter programs. A filter reads all of it's input, processes that input, then produces output. You will recreate 2 filter programs that are already available in Bash: nl, for numbering lines and wc, a word counting program.

Suppose you have a file named data.txt and it contains the following data: The quick brown fox jumped over the lazy dog. The nl command numbers the lines coming from it's input. Using the following command in bash: nl < data.txt Produces the following output: 1 The quick brown 2 fox 3 jumped over 4 the lazy dog. The wc command gives you the number of lines, words, and characters of the data that it reads. This command: wc < data.txt Will output: 4 9 46 Which means that data.txt contained 4 lines, 9 words, and 46 characters. For this lab you won't have to have your wc implementation count lines or characters, just words.

Exercise 1

Create a program that works like the nl command. Name your source file nl.cpp and name your program file nl.

Exercise 2

Create a program that counts the number of words it reads from standard input. Name your source file wc.cpp and name your program file wc.