CS Programming Assignment, Programming Language C

Assignment 1 Word Count

General Requirements

• Write a program that counts the number of characters, words, and lines in a file or group of files

• Subset of the standard Linux “wc” utility

• If no program parameters are specified then process standard input

• If program parameters are specified then they are the names of the files that are to be processed.

• If more than 1 file is processed then provide a total in addition to the individual file statistics

Threshold Requirements

• Character, Word, and Line count must match that given by wc for files that only contain printable characters (text files)

• Works on standard input if no files specified on the command line

• Works on a list of files specified on the command line

• Produce a summary total if more than one file is specified

• Include results that show that the results match wc

• Include results for: • standard input • 1 file on command line • multiple files on the command line

Objective Requirements

• No tabs in the source file

• Proper indentation

• Reasonable names for variables

• Proper submission format

• Produces the same character and line count as wc on binary files • The word count does not have to match

• The exact definition of a word as used by wc is obscure

How is this Different From “wc”?

• No options on the command line. All parameters are assumed to be filenames.

• Need not match the results of wc when processing files that contain non-printing characters.

• Otherwise, it should produce the same results

What is a “word”?

• Sequence of characters delimited by whitespace

• “man isspace” for definition of whitespace

abc123 1 word

a+b-c 1 word

a + b – c 5 words

Example Test

Now is the time

This is the place

2 lines

8 words

34 characters

State Machine for Recognizing Words

Start

Finish

In A Word

Not In A Word

is Space

++words

++words

Hints

• The following functions from the standard library may be useful: fopen

fgetc

isspace

• The following variable is available from the standard library FILE * stdin;

• Use man to get more information on these functions/variable

Submission

• Printed solution due by the end of class on February 5

• Solution is to include: • Source Code • Test Data • Screen shot of your results

• standard input • 1 file on command line • multiple files on the command line

• Screen shot of the same tests run with wc

• One of the tests is the source code for your program. Create at least one more.