EECS 2031 Software Tools, Winter 2014

Lab 3 (lab open during first 30 minutes, then closed in labtest mode)

Cellphones and other electronic devices must be off while you are in the lab.

Background Scenario

This lab uses the same bathroom scale data transmission scenario as lab2. However, this time you have to adapt your solution for lab2 to deal with data sent from a different bathroom scale, which transmits similar data with slightly different properties. That bathroom scale was made and programmed by a different manufacturer, who choose to interpret some parts in the protocol specification differently. The issue was only discovered after thousands of devices had already been shipped, so you now have to adapt the smartphone package that reads the data.

In the following and for ease of reading, the most important changes have been marked below with '***'. As before, each line of input contains the following information:

timestamp userID weight

There are one more space characters separating the three pieces of information, except that the userID itself may now contain one or more spaces (as in "1000 John Jack Smith 123.45"). *** The fields are defined as follows:

This protocol can be parsed deterministically, as the weight is the first numeric field after a sequence of text fields, e.g. as in timestamp userIDa userIDb userIDc userIDd weight

Objective

Now create a new ANSI-C program that does the following.

Requirements

Your program must the input read line by line from standard input. *** For the purpose of this lab, you do not need to worry about overflow. In other words, you can safely assume that timestamps are guaranteed to fit in 32 bit integers, userID's will not be longer than 1000 characters including spaces, and floating point numbers will fit into a ANSI-C float variable. You can also safely assume that there is always at least one (or more) space characters between the fields and between each part of the userID. Moreover, each line of input is guaranteed to be less than 1024 characters long.

Assuming that the program is started with lab3, and given the following input, which is also provided for convenience as a file input.txt:

3600  godzilla's kid 30.0
36000 godzilla 299
36001 godzilla's kid 30.1
36002 godzilla's  kid 30.2
36999 godzilla     30.2
60000 john jack       andrew wolfgang jiang rami      tom bob robert frank richard smith 123.5
your program should create the following output:
OK
OK
OK
Suspiciously large weight change
OK
OK

Hints:

Additional hints: