EECS 2031 Software Tools, Winter 2014

Lab 4 (lab open during first 30 minutes, then closed in labtest mode) Later: changed to open lab

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 and lab3. However, this time you have to adapt your solution for the previous labs so that your program identifies if the user name for a weight record is new or has been previously seen.

In the following and for ease of reading, the changes relative to lab3 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 and none of the parts of the userID can start with a digit or '.'.

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 lab4, and given the following input, which is also provided for convenience as a file input.txt (file updated):

3600  godzilla's kid 30.0
36000 godzilla 299
36001 godzilla's kid 30.1
36002 godzilla's  kid 30.2
46002 godzilla's       kid 30.1
46999 godzilla     30.1
60000 john jack       andrew wolfgang jiang rami      tom bob robert frank richard smith 123.5
your program should create the following output, provided for convenience as a file expectedoutput.txt:
OK newuser
OK newuser
OK
Suspiciously large weight change
OK
Suspiciously large weight change
OK newuser

Hints:

Additional hints: