Abstract
Write a simple character filter to "compress" a text sequence.Details
The program should convert sequences of three or more repeated characters (of all kinds, including special characters) to a representation of the form ~nc where n is the number (a single digit) of repeated characters and c is the character. A single tilde (~) in the input should be output as a double tilde. A double tilde in the input should be output as ~~~~. Sequences of more than nine repeated characters must be broken up into two or more sequences of 9 or less.
io:~% gcc -Wall -o p3 p3.c io:~% ./p3 abbcddddeffgfff abbc~4deffg~3f a~bc55555 a~~bc~55 abbbbbbbbbbbbbbbbbbbc a~9b~9bbc ~~ ~~~~ ~~~~ ~4~ CTRL-D io:~%While illustrative of compression, the above does not reflect actual end-of-line processing. The following is an actual transcript of running one solution interactively:
ceres 2% ./p3 abbcddddeffgfff a~bc55555 abbc~4deffg~3f abbbbbbbbbbbbbbbbbbbc a~~bc~55 ~~ a~9b~9bbc ~~~~ ~~~~ CTRL-D~4~ ceres 2% ./p3 hellllllllo worrrrrld but this is the end he~8lo wo~5rld~4 CTRL-Dbut this is the end ceres 2%Another valid example is the following, in which a different function for reading characters was used:
[brian p3]$ ./p3 abbcddddeffgfff abbc~4deffg~3fa~bc55555 a~~bc~55abbbbbbbbbbbbbbbbbbbc a~9b~9bbc~~ ~~~~~~~~ ~4~CTRL-D [brian p3]$In both cases the same set of input lines was provided, but because different system library functions were used, a different interactive output was generated. However, the same sequence of characters was generated to standard out in both cases.Submission Requirements
- As usual, the program must be named p3.c and must reside in the cse271.131/p3 subdirectory.
- Create and use an appropriate Makefile that will compile your program using make, and will clean the directory with make clean.
- Your name must be in the comment section.
- Do a touch DONE when the program is ready to be collected.