Intro to C #1: select-column

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

Goals

Rubric

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

Getting started with C

This term, nearly all of your work will involve the C programming language either directly or indirectly. As we get started with C, I am assuming that you have a working knowledge of both Python and Java, to the level they are taught in CS 111 and 201.

I also assume you will familiarize yourself with the program examples I provide on our Samples page. You should definitely study and play with those programs, and you may feel free to plunder them for code to use in your own programs.

Your first few homework assignments will focus on a few core C concepts:

CSV files

The input for your first program 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, print an empty line for that row.

Getting the starter package

For many assignments this term, you'll receive some starter code, some testing tools, or miscellaneous other materials to help you get started. These will generally be delivered to you via downloadable tar files. As noted in this handy tutorial from Indiana University, you can extract the files and folders contained in a tar file by using the command:

tar xvf whatever.tar

To get started on this first assignment:

Automated testing

In the select-column-package.tar file linked at the top of this page, you will find:

For most assignments, I will only give you very simple tests in the assignment's starter package. The grader and I will run some more sophisticated tests to explore the boundaries of a given assignment. You are, of course, free to use the testing infrastructure from the starter package to add your own tests. Getting used to automated testing and to writing detailed tests of your own will serve you well in the long-run.

Submitting your work

A little advice

Have fun!

Don't by shy about experimenting and asking lots of questions.