Intro to C #1: select-column

Starter code: select-column-package.tar
Upload solutions via as: select-column.tar

Goals

Rubric

0 - author name(s) in comment at top of your C source file 7 - program correctness 2 - code quality

CSV files

The input for the program you are about to write will come in the form of a comma-separated values file. CSV files give us a simple way of representing tables. Each line of text represents one row of the table, and each row is separated into columns by commas. For example, here is a simple CSV file animals.csv representing a table with a heading row followed by five data rows, with three data cells (or columns, if you prefer) per row:

Animal,leg count,eye count dog,4,2 emu,2,2 spider,8,8 ant,6,2 sea star,5,5

The official CSV format has to worry about whether any of the data in the cells contain commas, but we're not going to worry about that. For this assignment, you may assume that there are no commas in the data, so any comma in the CSV file marks a separation between adjacent data cells.

Programming assignment #1: select-column

For this assignment, you will write a C program select-column.c that takes a CSV file and a 1-based column number as command-line arguments, and prints the specified column of the file to standard output.

For example, suppose we run your program like so:

./select-column animals.csv 2

where the file animals.csv is as shown above. Then the expected output is:

leg count 4 2 8 6 5

If the specified column does not exist in a particular row of the file, your program should print an empty line for that row.

What to do

Note that I'm asking you to create a tar file instead of just submitting select-column.c directly because I want you to practice creating tar files in preparation for later submissions that may involve multiple files.

A little advice

Have fun!

Try stuff. Ask questions.