CMPS-2240 Lab 5
Read a file, parse numbers, do arithmetic

Gordon Griesel
Department of Computer and Electrical Engineering and Computer Science
California State University, Bakersfield

Part 1: Read a file and stop

We worked on this together in class.

The file we wrote, monday.s, is now available in a working form.
The new file is named: lab5.s

Get a copy of the file here:
/home/fac/gordon/public_html/2240/code/lab5/lab5.s

Do not overwrite your own monday.s program.

Copy the lab5.s program to mylab5.s and begin work.

Part 2: Read all the numbers in a file

What to do...

1. Run the program.
===================
   Make sure the program reads your local myfile.txt file.

2. The program will parse each word or number.
==============================================
   If your text file contains any numbers,
   accumulate the total sum of all the numbers in your file.

   Words will be ignored by atoi() function and return 0.

   A word beginning with numeric characters will be seen as a number by atoi().

      123go!      <---- will be seen as a number.
      testing123  <---- will be seen as a zero value.

3. When you get the program working, comment-out any debug output.
==================================================================

4. Update the notes at the top of the program to show register use.
===================================================================

5. The delimiter between words is not just space, but whitespace.
=================================================================

Try to do these features. May become homework.

6. Add an option to the program.
================================
   Allow the user to specify the text file-name on the command-line.

7. Check for error when opening the file.
=========================================
   Print a message showing "File open error!" or something similar.

When I run your program, the text file might look like this:
==================================================================
| This is my text file. Here are some numbers: 1 2 3             |
| Here are some more numbers: 123 456 2 9 45                     |
| One more number: -6                                            |
| End of file.                                                   |
==================================================================
The sum should be: 635

There are several correct ways to get this program done, and to show the output.

sample output:

$ spim -f mylab5.s

Sum of numbers is: 635

For a higher score, do one of these output formats:

$ spim -f mylab5.s

123 456 2 9 45
sum: 635 


$ spim -f mylab5.s lab5.txt

123 + 456 + 2 + 9 + 45 = 635 


$ spim -f mylab5.s myfile.txt

 123
 456
   2
   9
  45
----
 635 

What to turn in

Files on Odin to be collected at 12:30pm...

   2240/5/monday.s
   2240/5/lab5.s
   2240/5/mylab5.s
   2240/5/myfile.txt