Computer Science 381
Programming Unix in C
Winter Immersion 2016, The College of Saint Rose
In this lab you will gain more experience with the Unix tools and techniques from last week, but the focus is on some of the basics of C programming.
Before you start, create a directory on a Unix or Mac system to contain your work for this lab, and open a file lab2.txt where you will place your answers for this lab's questions.
C Basics
You may work on any C-capable Unix-like system (such as a lab Mac, mogul, or your own Unix-like system).
If you have not already done so, finish reading Chapter 1 of K&R.
To run your program, we'll use Unix redirection like we did for the
previous lab's output captures. Those used only output redirection
with >
at the end of the command line. We can also perform
input redirection with <
after our program name. This
lets you run a program that expects input from the keyboard but
instead that input will come from the file. For this case, copy the
file on mogul in
/home/cs381/labs/c-basics/whosonfirst.txt to your directory for
this lab. Then run your practice program, redirecting its input from
whosonfirst.txt and its output to a file whocounts.txt with
a command such as
./charcount < whosonfirst.txt > whocounts.txt
Note: the getline function is now defined in stdio.h. (check text for what it was previously)
Also run this program on the whosonfirst.txt file, this time saving the output in whorev.txt.
Programming Assignment
Write the program in Exercise 1-20 on p. 34 of K&R. Call your program detab.c. Use a defined constant for the value n, the number of columns between tab stops. Include This program is worth 20 points, broken down as shown at the end of this document.
Reference solutions to all programs are available on mogul in /home/cs381/labs/c-basics.
Submission
Please submit all required files as email attachments to terescoj AT strose.edu by Wednesday, December 23, 2015. Be sure to check that you have used the correct file names and that your submission matches all of the submission guidelines listed on the course home page. In order to email your files, you will need to transfer them from mogul to the computer from which you wish to send the email. There are a number of options, including the sftp command from the Mac command line.
Grading
This lab is graded out of 50 points.
Grading Breakdown | |
Lab questions and output captures | 10 points |
Practice program charcount.c correctness | 10 points |
Practice program revlines.c correctness | 10 points |
detab.c correctness | 10 points |
detab.c design | 3 point |
detab.c documentation | 3 points |
detab.c style | 3 point |
detab.c efficiency | 1 point |
Total | 50 |