19.B: Programming Courtesy | 19: Running C | 19: Running C |
Once you have gone through the trouble of writing a program, you should enjoy the excitement of running it. The most common Unix C compiler is cc
> cd ~/development/prog
> cc myprog.c
Here myprog.c is the name of the file containing the C source code of the program you wish to compile.
If your program does not contain serious errors, this command produces a file a.out. If your program is complete (and not just a procedure, for example), a.out will be executable version of area.c. If your program is not complete, a.out will contain an object code version of it. To run the executable, just enter a.out
> a.out
The name a.out is not terribly descriptive, so Unix gives you the option (-o) of naming your objects as you compile them:
> cc myprog.c -o it-runs
This compiles your C program into the object it-runs. If your object is executebale, you execute it just be entering its name:
> it-runs