News:

Build a stunning handcrafted website with IT Acumens

Main Menu

Using C with UNIX

Started by thiruvasagamani, Jul 17, 2008, 04:49 PM

Previous topic - Next topic

thiruvasagamani

A little knowledge is necessary before you can write and compile programs on the UNIX system. Every programmer goes through the same three step cycle.

   1. Writing the program into a file
   2. Compiling the program
   3. Running the program

During program development, the programmer may repeat this cycle many times, refining, testing and debugging a program until a satisfactory result is achieved. The UNIX commands for each step are discussed below.

Writing the Program

UNIX expects you to store your program in a file whose name ends in .c This identifies it as a C program. The easiest way to enter your text is using a text editor like vi, emacs or xedit. To edit a file called testprog.c using vi type


vi testprog.c

The editor is also used to make subsequent changes to the program.

The C Compiler (cc)

The simplest method is to type


cc testprog.c

This will try to compile testprog.c, and, if successful, will produce a runnable file called a.out. If you want to give the runnable file a better name you can type


cc testprog.c -o testprog

This will compile testprog.c, creating runnable file testprog.
Thiruvasakamani Karnan