6.4 Bowling program6 Assignments6.2 Robots6.3 Character processing

6.3 Character processing

Looking through a stream of characters for a specific pattern or sequence is frequently done by computers. For an example, think about what a compiler does with a program. It needs to look for comments, operators, identifiers, and constants.

In this lab I want you to do a bit of text processing yourself. (Not quite a compiler for sure.) You can use your standard input, or if you wish to read ahead in your book and process the input from a file. Both approaches are fine. Extra credit will be given if you take the "UNIX" approach of looking on the command line for a file name, and if it exists use it, otherwise use the standard input (keyboard or redirected input).

At the start of your program print out:

Write a program that process an input stream doing the following:

After each line read it prints out the following information: At the end of the file print out the following totals: Hint:
#include <stdio.h>
#define TRUE 1
#define FALSE 0
main()
{
int c;
int comment = FALSE;
 while( (c=getchar()) != EOF )
  {
  if( c == ';' ) 
    {
    comment = TRUE;      
    }
  if( c == '\n' )
    {
    comment = FALSE;
    }
  if( comment == TRUE ) continue;
  putchar(c);
  }
}

Given the following example input.

This has a comment; And the comment is discarded. 101010010010
A hidden binary number 9991999; Of 1
1010109AAAA10; The last binary number is decimal 2 
This output should be in the following format:
No Binary Number       15 Letters           0 Digits
               1       19 Letters           7 Digits
               2        4 Letters           9 Digits
3 Lines --------------------------------------------
               3       38 Letters          16 Digits  
Test your program with the following sample data set.
; This is the test date for the lab "Stream"
; Louis Taber  3/29/98
; CSC130  Pima Community College
                           ; Blank Line
ABCDEFGHIJKLMNOPQRSTUVWXYZ ; Uppercase letters
abcdefghijklmnopqrstuvwxyz ; Lower case letters
1234567890                 ; Digits - binary number: 0
11111111                   ; Binary number 255
1000000000000000           ; This may give you 
                           ;   a negative number (OK)
                           ;   Do you know why?
10101010a10101010b111      ; Last binary number: 7
[]|--+=*#@                 ; Some special symbols
The last Line

It is available by anonymous ftp at
ftp://lt.tucson.az.us/pub/c/numbers.dat.

Turn in a copy of your program and its output when used with the above test data marked with:

Please turn your lab in to Pima Community College employee in room A-115 ofthe Santa Rita Building. Ask them to place it in the lab folder in Louis Taber's mailbox.
Instructor: ltaber@pima.edu ** My new Home at GeoApps in Tucson ** The Pima College Site

6.4 Bowling program6 Assignments6.2 Robots6.3 Character processing