CS 355 - Systems Programming Lab 5 - 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 [-rs]
-s switch sorts the filenames in the lexicographical order. The file names must be arranged in sequence so that the names in column 1 are followed by the names in column 2, and so on.
-r switch sorts the filenames in the reverse lexicographical order.
When no switches are present, myls2 does not need to sort the file names.
Consider using the qsort() library function that implements the quicksort algorithm to sort an array.
Use the hint on p. 164 to determine the width of the current terminal window.
Test myls2 using the files with names of varying length archived in this ZIP file.
$ ls
dirA file2.txt file5.txt file8.txt
file0.txt file3.txt file6.txt file9.txt
file1.txt file4.txt file7.txt
$ cd dirA
$ ls
file0a.txt file444444444a.txt file8a.txt
file1a.txt file5a.txt file9a.txt
file2a.txt file6a.txt
file3a.txt file7a.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.