CS 355 - Systems Programming Lab 7 - implementing multicolumn ls
Objective: write a program that can print the names of files in the current directory in multiple columns.
- Write a C program myls2 whose behavior resembles that of the system command ls. myls2 must print the names of files in the current directory in columns of equal width. myls2 must accept the following parameters:
$ myls2 [-ars] [directory]
Overall behavior of myls2 is identical to that of myls1 described in lab6.
myls2 needs to present its output using multiple columns of the same width as shown below:
$ myls2
dirA file2.txt file5.txt file8.txt
file0.txt file3.txt file6.txt file9.txt
file1.txt file4.txt file7.txt
$ myls2 dirA
file0a.txt file5a.txt
file0a_this_is_a_long_file_name.txt file6a.txt
file1a.txt file7a.txt
file2a.txt file8a.txt
file3a.txt file9a.txt
file4a.txt
Use the hint on p. 164 (Molay textbook) to determine the width of the current terminal window.
You are not allowed to use functions scandir(), alphasort(), versionsort() or similar functions.
Test myls2 using the files with names of varying length archived in this ZIP file.
Use the following test cases when running myls1 from the directory at the same level with dirA:
$ myls2
$ myls2 dirA
$ myls2 -as dirA
$ myls2 -r dirA
Run each of the test cases above twice:
- in a relatively wide terminal window resulting in at least two rows of file names, and
- in a relatively narrow terminal window resulting in at least four rows of file names.
- A single C source code file with your work.
- Several screenshots (in PNG or JPG format) showing the results of executing all test cases listed above on a Linux terminal.