CSC/CPE 3350 Lab 2

Download Solution: Click to Download Solution
Solution File Name: 1_A.zip
Unzip Password: prestobear.com

Problem:
In this lab, you will implement your own versions of some popular Linux programs. All programs must
be written in C. No C++ or other languages are allowed. All programs must be built and tested on
luke – your code must work on luke, I will not test it elsewhere.

You will be working individually for this lab. You may discuss high-level concepts with other students,
but you should never share solutions or show each other code.

There are three requirements for this assignment that contribute to your final grade: the programs
themselves, comments and style, and GitHub commits.
1. (60 points) The Programs
Note: parameters in [] are optional, parameters in <> are required. The | (pipe) means “or.”
new_cat (10 points)
-Usage: ./new_cat [file.txt]
-If the [file.txt] argument is passed, open the file and print it to stdout. If there is no
second argument, repeat what the user types on stdin back to stdout (until the user hits
CTRL+D to indicate EOF).
-Make sure to compare your output to cat. Note this is not exactly like cat: only one file
argument should be accepted, and we are not implementing the various command line flags.
-Make sure to fail gracefully if the file does not exist or if > 2 arguments are passed.

new_echo (10 points)
-Usage: ./new_echo [arg] [arg] … [arg]
-Print all [arg] arguments to stdout.
-If there are no [arg] arguments, simply print a newline and end the program.
-Make sure to compare your output to echo. Note this is not exactly like echo, since we are
not implementing the various command line flags.
-Make sure to fail gracefully as needed (no specific requirements).

new_tail (15 points)
-Usage: ./new_tail [-n N] [file.txt]
-If [file.txt] is specified, print the last N lines of that file (default is 5 lines if -n is not
used). Otherwise, read from stdin until the user hits CTRL+D, and print the last N lines typed
by the user.
-If the [-n N] flag is used, print the last N lines.
-The [file.txt] and [-n N] order should not matter – both orderings should be allowed.
-Make sure to compare your output to tail. Note this is not exactly like tail: only one file
argument should be accepted, and we are not implementing the various command line flags
(except for -n). In addition, tail by default prints the last 10 lines, new_tail prints 5.
-Make sure to fail gracefully if the file does not exist, if too many (or too few) arguments are
passed, or if the argument order is wrong (e.g., ./new_tail -n file.txt 10).

new_wc (20 points)
-Usage: ./new_wc [-l|c] [file.txt]
-If[file.txt] is specified, print a count of the number of words in file.txt.
-If no [file.txt] argument is specified, read from stdin until the user hits CTRL+D.
-If the -l (lowercase L) flag is specified, print the number of lines and the number of words.
-If the -c flag is specified, print the number of characters and the number of words.
-For simplicity, only let the user enter one of -l or -c (not both).
-The [file.txt] and [-l|c] flag order does not matter.
-Note this is not exactly like wc: only one file argument should be accepted, and we are not
implementing the various command line flags (except for -l and -c).
-Make sure to fail gracefully if the file does not exist, or if too many (or too few) arguments are
passed.

Add Comment