Notice that cc displays the name of each source file it compiles. This way, if errors occur, you know where they occur. Also, the diagnostics mention the name of the source file.

#include <stdio.h>

/* contains standard I/O defs */ int sum_n( int n )

/* sum numbers from n to 1 */

{

int sum = 0;

/* running total; initially 0 */ for (; n >= 1; --n)

/* sum from n to 1 */ sum += n;

/* add n to sum */ return sum;

/* return the value of sum */

}

int main()

/* begin main program

*/

{

int n;

/* number to input from user */ printf("Enter a number: ");

/* prompt for number */ scanf("%d", &n);

/* read the number into n */

printf("Sum 1 to %d: %d\\n", n, sum_n(n)); /* display the sum */

}

Generally speaking, the compiler reads one or more source files, one of which optionally contains a main program, and outputs an executable named a.out by default unless a name is specified, as shown in Figure 1.

Compiling Programs on HP-UX: An Example 17