Schwartz & Christiansen Chapter 10 Exercises
1. Write a program to read in a filename from STDIN, then open that file and
display its contents with each line preceded by the filename and a colon.
For example, if fred was read in, and the file fred consisted of the three lines
aaa, bbb, ccc, you would see:
fred: aaa
fred: bbb
fred:, ccc
2. Write a program taht prompts for an input filename, an output filename, a
search pattern, and a replacement string, and replaces all occurrences of the
search pattern with the replacement string value copying the input file to
the output file. Try it on some files. Can you overwrite an existing file? Don't
try it with anything important!) Can you use regular expression characters
in the search string? Can you use $1 in the replacement string?
3. Write a program to read in a list of filenames and then display which of the
files are readable, writeable, and/or executable, and which ones don't exist.
(You can perform each test for each filename as you read them, or on the
entire set of names when you've read them all. Don't forget to remove the
newline at the end of each filename you have read in.)
4. Write a program to read in a list of filenames and find the oldest file among
them. Print out the name of the file and the age of that file in days.
Questions about the questions? Send mail to Robert Katz: katz@cis.highline.ctc.edu
Last Update January 26, 2000