CS157: Intro to C, Part II

Spring 2018

HW 1

CS157 HW1: Command-Line Arguments and Scientific Data Types                

Description                

For this assignment you will write a program called dogs.c that uses command line arguments to get the names of file to process, read data from those files, and perform some trivial calculations.                 

Your program must run with one or more command-line arguments: the names of the files to process. Your program must ensure that at least one command-line argument is submitted to the program. If not, you must print an appropriate usage statement.                 

Data File                

The data files you must process should contain several fields in each line: a dog breed name, a range of weights, and “lb”, which means pounds. For example:                 

    Akita 75-120 lb
    Beagle 20.0-25.765 lb
    Bouvier 60-90 lb
    Bulldog 49-55 lb
    Cerberus 1000-2000 lb

Here’s another, less orderly but still valid, example:                 

    Bullmastiff 100-133 lb
        Chihuahua 2-6 lb
    Collie 0000050.246813579-75 lb
      corgi            24-30                   lb
    woof 17.4128767-18.4128767 lb
    Wh!pP3+ 25-45 lb

Your program must work on these files or other such files, no matter what their filenames are. It should print the breed name, range of weights in pounds, and the range of weights in kilograms. For the purpose of this assignment, there are 0.453 592 37 kg in a pound.                 

Sample Run                

% cat dog-weights
Dalmatian 55-55 lb
Doberman 66-88 lb
Maltese 6.5-9 lb
Papillon 7-10 lb
Beagle
Pekingese 8-10 lb
Beagle fish
Beagle 10
Beagle 10-
Beagle 10-fish
Beagle 10-99
Beagle 10-99 fish
Whippet 25-45 lb
% c11 -Wall dogs.c
% ./a.out dog-weights
Dog Breed               min(lb)    max(lb)    min(kg)    max(kg)
---------               -------    -------    -------    -------
Dalmatian                 55.00      55.00      24.95      24.95
Doberman                  66.00      88.00      29.94      39.92
Maltese                    6.50       9.00       2.95       4.08
Papillon                   7.00      10.00       3.18       4.54
./a.out: Bad line 5 in dog-weights
Pekingese                  8.00      10.00       3.63       4.54
./a.out: Bad line 7 in dog-weights
./a.out: Bad line 8 in dog-weights
./a.out: Bad line 9 in dog-weights
./a.out: Bad line 10 in dog-weights
./a.out: Bad line 11 in dog-weights
./a.out: Bad line 12 in dog-weights
Whippet                   25.00      45.00      11.34      20.41

Debugging                

If you encounter “STACK FRAME LINK OVERFLOW”, then try this:

    export STACK_FRAME_LINK_OVERRIDE=ffff-ad921d60486366258809553a3db49a4a

Requirements                

How to submit your homework:                

    ~cs157/bin/checkin HW1 dogs.c

How to receive negative points:                 

Turn in someone else’s work.

User: Guest                 

Check: HTML CSS
Edit History Source

Modified: 2018-04-01T14:45                 

Apply to CSU | Contact CSU | Disclaimer | Equal Opportunity
Colorado State University, Fort Collins, CO 80523 USA
© 2018 Colorado State University
CS Building