CMSC 15200 - Summer 2013

Homework #6 (Short) Due: Saturday August 24th, 2013 @ 11:59 pm

In this homework, you will given the chance to gain experience reading/writings from/to files.


Problem #1: File Concatenation (fcat.c)

Write a program called fcat that "concatenates" any number of files by writing them to standard output, one after the other, with no break between files. For example, the following command will display the files f1.c, f2.c, and f3.c on the screen.
./fcat f1.c f2.c f3.c

Write this program in a file called fcat.c .

Hint: fcat needs only a single file pointer variable. Once its finished with a file, fcat can use the same variable when it opens the next file.


Problem #2: Phone Numbers (phone.c)

Write a program that reads in a series of phone numbers from a file and writes them in a standard format to another file. Each line of the file will contain a single phone number, but the numbers may be in a variety of formats. You may assume the each line will be no more than 30 characters long and will only contain 10 digits, possibly mixed with other characters (which should be ignored). For example. suppose that the file contains the following lines:
404.817.6900 (215) 686-1776 312-456-3242 844 534 3342 612345 6542
The output should be saved to another file and is required to have the following apperance:
(404) 817-6900 (215) 686-1776 (312) 456-3242 (844) 534-3342 (612) 345-6542

Have the program obtain the input and output file names from the command line.

Hint: You might find this function useful sscanf, especially with "%c".

Write this program in a file called phone.c


Problem #3: Word Count (words.c)

Write a program that reads in a file and prints out the number of times each word appears. A word in this case is any sequence of upper and lower-case letters that has a space before or after the sequence. Your program should not make any assumption about the maximum length of a word in the input file. This program is case-insensitive; that is, if two words differ only in that one has upper-case letters where the other has lower-case letters, then the words should be regarded as equal. Also, any other characters, such as, !, % ? should be ignored.

You may assume that a file contains at most 10,000 different words. If your program is given a file that contains more than 10,000 different words, it should print a warning message and then ignore any new words after the first 10,000. But still print out the counts for the 10,0000 words.

Write this program in a file called words.c


Style

At the top of each file, write a comment with your name, etc., in the following form:

              /* Jane Doe, jdoe */
              /* CS152, Summer 2013 */
              /* Homework 6: Problem # */
              
This information is not strictly necessary, since your files are already identified by their names and the repository they reside in. Nevertheless, the redundancy is a helpful convenience for us when we are browsing and/or grading your work.

Comments, where they occur, should be helpful and precise. Omit superfluous comments:

              int a = b + c; /* I'm adding b and c and naming it a! */
              
Yes, we can see that.

Your code should be no more than 80 columns wide.

Do not write more than one statement on a line.

Do not submit code that does not compile. If a function is broken, and makes compilation impossible, comment out that function and submit the rest. Non-compiling code will receive little to no credit.


Submitting Your Work

Save and commit your files in YOUR-REPOSITORY/hw6. Recall that you will need to add your work before you commit it. (Also, notice that in the -m message you include at commit time, -m is simply a command-line option.)

Commit your work early and often. We do not grade intermediate commits, only the work as it stands at the deadline. If you have any issues with subversion, not only your instructors but your classmates can help you. Most of the students in this class have at least one full quarter of experience running subversion.

If, for any reason, perhaps due to a late add, you do not have a CS repository, save your work somewhere you can easily get it and send mail to Adam. We'll get you set up with a repository in time to make the deadline.