Schedule
Labs
Assignments
TA office hours
Topic videos
Some course notes
Extra problems
Lecture recordings
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.
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.)
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 %
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 amand "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.