Creating, Compiling, Linking and Executing of a C Programs


In this article firstly you can read how to invoke Turbo C, how to name programs, how to compile programs, how to link programs and finally how to execute programs.

Invoking Turbo C

To start Turbo C, firstly we move to the directory in which Turbo C is installed and then type TC at the DOS command prompt. If Turbo C is installed in the root directory C:\> then type TC as:

C:\>TC

After this as you press Enter key the Turbo C IDE (Integrated Development Environment) screen, that consists of a menu bar that contains menu options, such as File, Edit, Run, Compile, and so on, is displayed as shown in figure 1.

c1

It will mostly be blank, with the menu bar at the top and the status line on the bottom. The Turbo C includes all the facilities to develop and execute programs, such as editor, compiler, debugger, linker, and so on. The first character of each menu option is highlighted. You can select any menu option by pressing the ALT tab key and the highlighted character of the respective menu option. For example, if you want to select Run menu option then you will press the TAB key and key containing the R character simultaneously as - ALT + E.


Naming Our Source Program

Now we are ready to work under Turbo C IDE. After invoking the Turbo C we select NEW option from the File menu. An edit window will appear with the filename NONAME.C. Since it is the name specified by the Turbo C IDE, therefore you need to change this. For this we select the Save option from the File menu. As we do this a dialog box will appear that asks for the name of our source program in order to rename NONAME.C.

After this the new name, that is CHAP0101.C, will appear because we have changed the file name from the NONAME.C to CHAP0101.C. Now the cursor is placed in the upper-left corner of the Edit window. Now you can type your source program, chap0201.cpp as shown in figure-2 as written in the earlier section, using arrow keys, tab key and Enter key to move the cursor.

Once we complete our typing we should save it to the disk by selecting Save from the File menu, or by pressing the F2. It is a good habit to this before compiling and executing our program.

c2


Compiling the Source Program

To compile the source file, we select Compile from Compile menu and will press Enter key. If there is no syntax error in the source program then the resulting window shows- Warning: 0, Errors: 0 and finally Success: Press any key. This compilation process creates an object file, which has an extension OBJ.

However if there is any error then the compiler displays the appropriate error messages, called diagnostic messages, that tells the cause of the error and the compilation process terminates. Therefore go back to the source program, correct it and compile it again. You can also compile the source program by pressing the ALT and F9 keys simultaneously.

Figure-3 shows various stages of compilation of a C++ program.

c3

Linking the Program

Once the source program has been converted into an object file, it is still not in the form that you can run. The reason behind this is that there may be some references to standard library functions or user-defined functions in other object files, which are compiled separately. Therefore these object files are to be linked together along with standard library functions that are contained in library files. To link our object file, select Link from the Compile menu. After this the .OBJ file will be compiled with the one or more library files. The result of this linking process produces an executable file with .EXE extension. Figure-4 depicts this linking process.

c4

 

This chap0201.exe program is a standalone executable program, which you can directly execute at command prompt as:

C:\TC> CHAP0201

This will execute the program and the results will get displayed on the screen.

Executing (Running) the Program

To execute (run) the .EXE file, select Run from RUN menu and press Enter key. The result will be displayed on the screen and controls returns back to the editing screen. However you can also execute the .EXE file by pressing CTRL and F9 keys simultaneously. To see result select User Screen from RUN menu or by pressing ALT and F5 keys simultaneously.


 


Like it on Facebook, Tweet it or share this article on other bookmarking websites.

No comments