CMPS-2240 Lab 6
Removal of Whitespace

Eddie Rangel
Department of Computer and Electrical Engineering and Computer Science
California State University, Bakersfield

Notice:
Due: Wednesday Oct. 18th by 4pm

Introduction

Goals:
Modify a character string.
Remove the trailing whitespace from the string.
This is a right-trim function.

Resources:
Please refer to all the resources on our home page.

Files Needed:
chop.s
rev.s
read.s

Copy all the files like this...
scp sleipnir.cs.csubak.edu:/home/stu/eddie/public_html/cmps2240/code/lab7/* .

Lab details:

Your task is to write a program rtrim.s that trims the whitespace off a word entered from the keyboard. Start by copying the two example files into your directory.

chop.s shortens a string by inserting a '\0' (NULL character) into the string. This effectively chops the string off. rev.s reverses the characters in a string. The algorithm takes two pointers, one starting at the end of the string and one starting at the begining of the string. It swaps the two characters at the top and bottom location. It moves the pointers 1 character (a byte) towards each other. It swaps the two characters at that location. It moves the pointers toward each other, swaps the two characters, so on and so forth until the pointers hit each other.

Your job is to write a program rtrim.s that removes trailing whitespace. Everything you need to do this is in rev.s and chop.s.

Use chunks of these two sample programs. You can grab the code to prompt the user for a string from read.s.

To demonstrate that you trimmed the white space, display the string followed by a period (if the period does not have any whitespace before it you know your code works). The code should execute as follows:


$ spim -f rtrim.s

Enter a word followed by some whitespace: foo[Tab]      [Tab][Enter]
foo.


What to turn in

Your lab program rtrim.s must be in the correct directory on Sleipnir.
directory name: /home/stu/you/2240/7/
Replace you with your own Sleipnir username!