Introduction
Announcements

Schedule
Labs
Assignments
TA office hours

Tests, exam

Topic videos
Some course notes
Extra problems
Lecture recordings

Discussion board

Grades so far

CSC 209 extra problems regarding software tools

1. Write a C program which acts as a standard unix tool (i.e. takes file name arguments or stdin if no args; outputs to stdout; etc) which turns all funny characters in its input to visible sequences as follows:

solution


2. Write a C program to calculate byte frequencies of the input, like this:

% echo helloooooo | bfreq
012: 1
e: 1
h: 1
l: 2
o: 6
% 
Use isprint() to make the decision as to whether to use %c or 0%o before the colon.

solution

2b. Write a command-line which sorts the occurrences into frequency order using sort. (Be sure that a frequency of 15 is sorted after a frequency of 7, despite occurring earlier in alphabetical order.)

solution


3. Command-line arguments are file names. Stat them and decrease their mtime by one hour using utimes(). Example session:

% ls -l foo
-rw-r--r--    1 ajr      instrs       1759 Apr 14 11:29 foo
% back1 foo
% ls -l foo
-rw-r--r--    1 ajr      instrs       1759 Apr 14 10:29 foo
% 

solution


4. Write the "nth" command, which outputs the nth field of each line (one-origin), based on a strtok-like delimitation of fields. It prints a blank output line when the input line has fewer than the specified number of fields.

Similar to grep, the first non-option argument is the n, and subsequent non-option arguments, if any, are the names of files to be processed. If there are no file names listed, the standard input is processed.

Example:
If the input consists of the two lines

    Hello, world, how are you
    today?  Myself, I am a C program with no feelings.
then "nth 4" would produce the output
    are
    am
and "nth 7" would produce a blank line and then the line "program".

[solution]


5. Write simple versions of any of the following unix tools. That is, implement a minimum of the command-line arguments or other special processing; mostly, just do the simple case, and you can impose arbitrary limits if necessary.