Lab03 - Files, error handling
Due:
Tue, Feb 22, 2022 at 11:59 PM
to Github Classroom Assignment
Background
In C, it’s very important to be careful when allocating memory, copying data between buffers, and working with files. In this lab, we will explore some common error handling techniques.
Requirements
- You will build a C program named
lab03
which- takes a filename and the name and quantity of a product for stock-keeping
- writes a comma-separated list of the data out to the file.
- Each product will have a name (at most 15 chars and a NUL) and quantity (an integer), and you will keep those in one or more C
struct
. It’s possible to generate the output without structures but please learn to use structures - You will use the C file management functions to open, write, and close the CSV file
- You will handle error conditions exactly as shown in the example output
- You will provide a
Makefile
and test your project with thegrade
script
Given
- I will discuss and demo the C file management functions in lecture.
Example Output
phpeterson@vlab20:lab03 $ ./lab03 lab03.csv
usage: lab03 filename 'name qty' ['name qty']
phpeterson@vlab20:lab03 $ ./lab03 lab03.csv 'apples 20' 'oranges 10'
phpeterson@vlab20:lab03 $ cat lab03.csv
name,quantity
apples,20
oranges,10
phpeterson@vlab20:lab03 $ ./lab03 lab03.csv 'apples 20' 'oranges asdf'
not a number: asdf
phpeterson@vlab20:lab03 $ ./lab03 lab03.csv "cinnamonapplessauce 10"
string overflow: cinnamonapplessauce 10
phpeterson@vlab20:lab03 $ ./lab03 /usr/bin/lab03.csv 'apples 20' 'oranges 10'
failed to open: /usr/bin/lab03.csv
Rubric
- For 80 points, pass the correctness tests
- For 90 points, pass the correctness and error handling tests
- For 100 points
- Write readable code (consistent naming and indentation, some comments, whitespace around conditionals and operators)
- Submit a clean repo (no build products)
- Correctly use
struct
, file management functions, and memory allocation functions