CIS 459.21 LAB4

*** Due Date: Friday 6/3/2005 11:59pm ***


Points: 100 + 100


Email boxes often have a lot of mails. In this lab, you are hired as a system programmer to provide a utility command for people to read their email. The following is the content of a sample stripped maibox.

From Wed May 18 18:33:55 2005
Return-Path: <>

How are you? <Note: email body>

From Wed May 19 18:32:55 2005
Return-Path: <>

I am fine. <Note: email body>

As you can see, each email, in standard format, consists of HEADER and BODY. The HEADER consists of multiple consecutive, non-empty lines. However, it must start with a line that begins with "From ". After an empty line, the HEADER is then followed by the BODY of an email. After another empty line, the next email again starts with a line, "From ". Your utility should have the following behavior:

  1. When started, read from a mailbox and print out the ordered list of 'From ' lines from all the emails.
  2. Ask the user about which email he or she wants to read.
  3. When having received a choice, print out the BODY of that email.
  4. Repeat a) -- c) unless the user says 0, at which point your utility command exits.
For example, suppose the the sample mailbox has a name, mailbox.yuw, you will run as the follows:

% lab4 mailbox.yuw
1 From Wed May 18 18:33:55 2005
2 From Wed May 19 18:32:55 2005

Please choose which email you want to read:
How are you?
Please choose which email you want to read:
I am fine.
Please choose which email you want to read:
Thanks for using my simple mail reader. Bye.


  1. You are required to write a program that can do a) at least. That is to say, you mail reader can print out a list showing who has sent emails.
  2. Step b) carries extra credits: 100 points.
  3. You will receive 200 points from this lab if your command can do a) -- d).
  4. Another sample mailbox is here if you need additional test cases.


With your interests in 459.21, I am assuming you are interested in system programming. So you are required to meet the following requirements:

  1. Document your programs well.
  2. Following a good coding style (see course page for links to different coding styles).
    In the worst case, use the indent program to process your source file before your submission.
  3. Provide a Makefile that compile your API header and source files first, and compile the main program lab4.c in a separate step.
    Your Makefile must have at least two targets: lab4 and clean.
    A sample Makefile is provided here. A link to GNU Makefile manual is available here.


When you finish with the lab, you need to turn it in for grading. The submit command submits your lab electronically. You MUST use the submit command to turn in your labs. The format of submit command is as follows:

submit classname labname files-to-submit

where, to submit your first lab for this class, use the following command from the directory which contains source files (lab4.c and Makefile):

submit c459.21aa lab4 lab4.c Makefile

Last updated: Wed May 18 19:53:56 EDT 2005