| CSC 161 | Grinnell College | Spring, 2012 |
| Imperative Problem Solving and Data Structures | ||
This laboratory exercise provides practice with basic elements of writing, editing, compiling, and running programs written in the C programming language. This will use the quarts.c program, complete with annotations.
Open a terminal window and move to your C subdirectory for this lab.
Start emacs with the command:
emacs quarts.c &
Use the links for the reading to open the program quarts.c in your browser. Then copy and paste it into the emacs window.
Compile and run the program in your terminal window by typing:
gcc -o quarts quarts.c ./quarts
Run the program several more times by typing just ./quarts. (You need not compile the program each time — unless you have changed quarts.c.)
Make the following typographical errors in quarts.c, recompile, and observe what happens. In each case, check whether the program compiles, and whether the program runs. If the program does not compile, what happens if you try to run quarts?
Type a few characters into your program BEFORE any of the code.
Type a few characters into your program AFTER the code.
Type some extra words inside of your main method.
Misspell your variables.
Misspell your printed output.
Misspell the name of your main() method.
Misspell the name of the included library.
Write a C program that uses values for pints, quarts, and gallons and determines the corresponding number of liters. Use 4 quarts per gallon and 2 pints per quart. You should reference the annotations on quarts.c to properly print out your output.
Although you can name this new program whatever you like, you should end the file name with .c for two reasons:
You can identify the C programs quickly when you list files in your directory with the ls command.
emacs recognizes the .c extension as indicating a C program, and emacs adjusts its setting to aid your editing for that type of file.
Refine your emacs environment to help support C programming. In particular, set the following options in the "Options" menu.
When done, click the "Save Options" choice in the "Options" menu.
Reminder: Since emacs is a very powerful editor, sometimes you will hit an erroneous key, emacs will do something unexpected, and then you will wonder what is happening. In such cases, the keystroke combination <ctrl>-g will stop any editing process within emacs!
Write a C program that uses a value for the radius of a circle and computes the circle's area and circumference.
Experiment with the emacs editor, following the lab on the Emacs Text Editor by Marge Coahran.
Development of laboratory exercises is an iterative process. Prof. Walker welcomes your feedback! Feel free to talk to him during class or stop by his office.