CS1101C Practical Exam

Question 4 (xxxx - xxxx hours)

Repeated Character Encoding

The name of your C program file must be called decode.c, files with any other name will not be marked.

The deadline for this lab is Wednesday 12 November 2008, xx:xx:xx hours. Strictly no submissions will be accepted after the deadline.

Many encoding systems have been designed to encode strings with many repeated consecutive characters. Here, we will decode a very simple encoding system.

Let us look at the following examples. In each of the following, you are given an alphanumeric string. If it contains any digits or the full-stop, then you will need to decode it. Display the decoded string.

Text File

Assume that the text file containing the encoded strings is always called “format1.txt” and that this file always exists. (It has been copied into your directory by the “pesetup” command.) Let us look at the file's contents:

abcdeeefg
abcde3efg
abcde3e2fg
cb2crf12
cb1crf12hg.
ca3b11e3ikf.gh4
Each line consists of an encoded string that you must decode. You may assume that the encoded strings consists only of lowercase letters, digits, and the full-stop. You may also assume that the full-stop will never come before a digit in the string. The encoded string has at most 60 characters.

Your task is to read each encoded string from the text file and display the results on the screen as shown:


Processing abcdeeefg:
abcdeeefg

Processing abcde3efg:
abcdeeeefg

Processing abcde3e2fg:
abcdeeeeefg

Processing cb2crf12:
cbbcrffffffffffff

Processing cb1crf12hg.:
cbcrffffffffffffhgggggggggggg

Processing ca3b11e3ikf.gh4:
caaabbbbbbbbbbbeeeikfffghhhh

Note that the number of lines in the text file is not known. You are to read the file until you reach the end of the text file.

Important Notes

Do not use any structures or any form of dynamic memory allocation (using malloc or calloc) in your program, else no credit will be given.

Remember to submit your program frequently using the submit decode.c command, and check your submission using the check command.

All the best!

UNIX commands

Some useful UNIX commands (in case you forgot what you did in Lab 0):

  1. dir”: lists all the files in the directory.
  2. cp a.txt b.txt”: copies a.txt to b.txt.
  3. mv a.txt b.txt”: moves / renames a.txt to b.txt.
  4. cat a.txt”: shows the contents of a.txt.