CSC 201 Grinnell College Spring, 2005
 
Data Representation, Memory Management, and Formal Methods
 

Multi-Processing Application: Counting Sentences and Words in a File

Goals

This lab ties together several components of this course, including multi-processing, communication between processes using shared memory, access of files, character processing, and the use of loop invariants to develop programs.

Problem

Write a program that reads a text file and computes the following basic analysis of sentences and words:

Definitions

While a careful analysis of words and sentences might require complex rules on sentence structure, work for this lab depends on the following simple rules.

Words: A word is defined as any of the following:

Sentences: A sentence is defined as

Examples

Here are three sentences, each with exactly eight words:

Work for this Lab

Program ~walker/c/concurrency/read-write-2.c contains version 2 of the Readers-Writers problem from the class concurrency handout, with minor modifications for Linux and for output. Using this program as a base, this lab asks you to make the following modifications:

  1. Change the buffer size and/or access as needed, so that the Writer will place character data in the buffer rather than integers, and so that the Reader will extract this character data. (The in and out pointers will still need to specify logical integer addresses, but buffer will need to be an array of characters.)

  2. Modify the Writer process, so that it reads a file name from standard input, then reads successive characters from this file, and places those characters in the buffer. When the file has been completely read, the Writer should place an EOF character in the buffer before it terminates.

  3. Modify the Reader process, so that it reads successive characters from the buffer and processes each character as needed. Two types of output are required:
    1. When a sentence is completely read, the Reader should print the sentence number and word count for that sentence.
    2. When all sentences are read, the Reader should print the total number of sentences and the average number of words per sentence.

Notes:

Work to turn in


This document is available on the World Wide Web as

     http://www.cs.grinnell.edu/~walker/courses/201.sp05/lab-multi-processing.shtml

created December 10, 2001
last revised February 11, 2005
Valid HTML 4.01! Valid CSS!
For more information, please contact Henry M. Walker at walker@cs.grinnell.edu.