CS 355 - Systems Programming Lab 5 - implementing cat
Objective: write a program that can concatenate and print files.
- Write a C program mycat whose behavior resembles that of the system command cat. Unlike the standard cat, mycat will not work with the standard input. mycat must accept the following parameters:
$ mycat [-bens] file1 [file2 ...]
mycat must receive at least one parameter, file1, whose content will be printed on the screen. If more than one file name is specified, the contents of all of the files will be printed.
mycat must accept any combination of the following switches, which are somewhat different from the standard version of cat:
- -b Number the non-blank output lines, starting at 1.
- -e Display a dollar sign ('$') at the end of each line.
- -n Number the output lines, starting at 1.
- -s Squeeze (remove) all empty lines, causing the output to be single spaced. An empty line can contain one or more whitespace characters (e.g. space, tab, newline, carriage return).
You may not use fopen() and fgets() to read the data from input files.
Test mycat using the following text files: file1.txt, file2.txt, and file3.txt. Use the following test cases:
$ mycat file1.txt
$ mycat file1.txt file2.txt file3.txt
$ mycat -n file1.txt file2.txt
$ mycat -b file1.txt file2.txt
$ mycat -bn file1.txt file2.txt
$ mycat -e file1.txt file2.txt
$ mycat -be file1.txt file2.txt
$ mycat -es file1.txt file2.txt
$ mycat -ens file1.txt file2.txt file3.txt
- A single C source code file with your work.
- Several screenshots (in PNG or JPG format) showing the results of executing the test cases listed above on a Linux terminal.