Monday, 5 September 2016

Creating and Running C Program

Executing a program written in C involves a series of steps these are
i) Creation a program
ii) Compiling the program
iii) Linking the program
iv) Executing a program

i) Creating the program : The programming process starts with creating a source file that consists of the statements of the program written in C language. This source file usually contains ASCII characters and can be produced with a text editor, such as Windows notepad, or in an Integrated Design Environment. Create a text file with its name editing with a ‘C’ extension and type a C programming that file.

       In case of Turbo C package, The program can be typed using built-in editor. If the operating system is Unix, the program can be typed using EDI or Vi text editor.

ii) Compiling the program: The source file is then processed by a special program called a compiler. The compiler translate the source code into an object code. The object code contains the machine instructions for the CPU and calls to the operating system application programming interface (API)

        The compilation command under Unix is $cc file name.
Steps in creating and Running C Program

Turbo C compiler is under friendly and provides integrated program development environment. Thus compilation can be done by selecting environment. Thus compilation can be done by selecting appropriate menu options.

The translation is done after examining each instruction for its correctness, if everything is alright the composition proceeds silently and the translated program is stored an another file with the name filename. Obj.

iii) Linking the program: Linking is the process of putting together other program files and functions that are required by the program.

              For example, if the program is using sqrt () function, then the objet code of this function should be brought from the math library of the system and linked to the main program.The compiled and linked program is called the executable code, and stored automatically filename, exe or in UNIX file named a.out.

iv) Executing a program : In unix operating system the program can be executed with the executable file a. out, by typing a. out at system prompt$

                  In Turbo C environment, the RUN option will do the compilation and executing of a program.
During execution, the program may request for some data to be entered sometimes, the program does not produce the desired results. Then it is necessary to correct the source program (or) the data. In case the source program is modified, the entire process of compiling and executing the program should be repeated.

The different files used in the above process are

1.Source code file: the source code file contains the source code of the program. The file extension of any C source code file is ‘ c ‘. This file contains C source code that defines the main function and may be other functions.

2. Header files: When working with large projects, it is often desirable to separate out certain sub routines from the main () of the program. There also may be a case that the same subroutine has to be used in different programs.

So, the option is to make subroutines and store them in a different file known as header file. The advantages of header files are

• The programmer wants to use the same subroutine in different programs. For this, one simply has to compile the source of code of the subroutines once, and then link to the resulting object file in any other program in which the functionalities of these sub-routines are required.

• The programmer wants to change or add subroutines, and have those changes reflected in all the other programs. In this case, one just needs to change the source file for the subroutines, recompile its source code, and then recompile and re-link programs that use them.

3.Standard header files: Functions that are provided by all C Compilers are included in standard header files. Examples of these standard header files include the following:
• Sting.h : for string handling functions
• Stdlib.h : for some miscellaneous functions
• Stdio.h : for standardized input and output functions
• Math.h : for mathematical functions
• Alloc.h : for dynamic memory allocation
• Conio.h : for clearing the screen
All the header files are referenced at the start of the source code file that uses one or more functions from that file.
3. Object files: Object files are generated by the compiler as a result of processing the source code file. They contain compact binary code of the function definitions. Linker uses this object file to produce an executable file (.exe file) by combining the object files together. Object files have a .’O’ extension, although some operation systems including Windows and MS-DOS have a ‘.obj’ extension for the object file.

4. Binary Executable file: The binary executable file is generated by the linker. The links the various object files to produce a binary file that can be directly executed. On windows operating system, the executable files have .’exe’ extension.

0 comments:

Post a Comment

Scribe to Youtube Channel

Advertisement

Find Us On Facebook

C Programming

More

C++ Tutorial

More

Java Tutorial

More

software engineering

More

MS Office

More

Database Management

More
Top