![]() | ![]() | ![]() | 6.4 Character processing |
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 processes an input stream doing the following:
#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 2This 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:
![]() | ![]() | ![]() | 6.4 Character processing |