Homework 7

Due date

This assignment must be submitted as a single file name countreal.c for Homework 7 of the ECE 209.602 / CSCI 373.002 section on UNCA moodle by 11:00 PM on Wednesday, 27 October.

The setup

The Pascal programming language had a format for real literals similar to C double literals, but with one important difference: If there was a decimal point in the number, there had to be digits both before and after the decimal point.

Consequently, the following are legal real literals in Pascal.

And, the following are not legal real literals in Pascal.

Incidently, -6e9 isn't really a literal in C. It is an application of the negation operator to 6e9, which is a double literal. It's a fine distinction, but it makes the assignment easier.

The assignment

Write a program that reads a series of input lines. On each input line your program will count (1) the number of "words" on the line and (2) the number of those "words" that were legal Pascal real numbers. For the purpose of this assignment, a word is a sequence of characters that aren't white-space characters, but either begins or ends the line or is surrounded by white-space characters.

After each line, your program should print the number of the line along with the number of words and the number of Pascal real literals the line contains.

When your program reads an end-of-file, it terminates immediately.

For example, if your program reads the following sequence of five input lines.

as easy as 3.14

1. .1 .1e1
  1.0 0.1 100.00e123971293791273897 ain't that big
w h e w !

Your program should output something like the following.

Line  1:  #Words   4, #REAL   1
Line  2:  #Words   0, #REAL   0
Line  3:  #Words   3, #REAL   0
Line  4:  #Words   6, #REAL   3
Line  5:  #Words   5, #REAL   0

Under no conditions should your program "bomb". It must handle any input gracefully.

Starting points

Use the following three files to start your program.

One more rule

You may not use lexical analysers, like lex or flex, to generate your code.

Clarifications and suggestions

Do not use the scanf operator to see if the word is a real. That won't work, because a Pascal real is not a C double.

Do not use arrays. If you do, your program will not work for really long real literals, such as 1000000000000000000000000000000e123971293791273897.

Use a state machine as discussed in the Homework 7 hint.


10 File submitted with proper name
10 Compiles with no warning using -pedantic or -std=c99
5 Proper indentation
5 Reasonable comments
10 Program is well organized
30 Program runs on six easy test cases
30 Program runs on six devious test cases