[FrontPage] [TitleIndex] [WordIndex

Note: You are looking at a static copy of the former PineWiki site, used for class notes by James Aspnes from 2003 to 2012. Many mathematical formulas are broken, and there are likely to be other bugs as well. These will most likely not be fixed. You may be able to find more up-to-date versions of some of these notes at http://www.cs.yale.edu/homes/aspnes/#classes.

See HowToUseTheComputingFacilities for details of particular commands. The basic steps are

If any of these steps fail, the next step is debugging. We'll talk about debugging elsewhere.

1. Creating the program

Use your favorite text editor. The program file should have a name of the form foo.c; the .c at the end tells the C compiler the contents are C source code. Here is a typical C program:

   1 #include <stdio.h>
   2 
   3 /* print the numbers from 1 to 10 */
   4 
   5 int
   6 main(int argc, char **argv)
   7 {
   8     int i;
   9 
  10     puts("Now I will count from 1 to 10");
  11     for(i = 1; i <= 10; i++) {
  12         printf("%d\n", i);
  13     }
  14 
  15     return 0;
  16 }
count.c

2. Compiling and running a program

Here's what happens when I compile and run it on the Zoo:

$ gcc -o count count.c
$ ./count
Now I will count from 1 to 10
1
2
3
4
5
6
7
8
9
10
$

The first line is the command to compile the program. The second line runs the output file count. Calling it ./count is necessary because by default the shell (the program that interprets what you type) only looks for programs in certain standard system directories. To make it run a program in the current directory, we have to include the directory name.

3. Some notes on what the program does

Noteworthy features of this program include:


CategoryProgrammingNotes


2014-06-17 11:58