How to Compilation and Execution A C programming File ?

How to Compilation and Execution A C programming File

Once you have written the program you need to type it and instruct the machine to execute it To type your C program you need another program called Editor. Once the program has been typed it needs to be converted to machine language (Os and Is) before the machine can execute it. To carry out this conversion we need another program called Compiler. Compiler vendors provide an Integrated Development Environment (IDE) which consists of an Editor as well as the Compiler. 

There are several such IDEs available in the market targeted towards different operating systems. For example, Turbo C, Turbo C++ and Microsoft C are some of the popular compilers that work under MS-DOS; Visual C++ and Borland C++ are the compilers that work under Windows, whereas gcc compiler works under Linux. Note that Turbo C++, Microsoft C++ and Borland C++ software also contain a C compiler bundled with them. If you are a beginner you would be better off using a simple compiler like Turbo C or Turbo C++. Once you have mastered the language elements you can then switch over to more sophisticated compilers like Visual C++ under Windows or gcc under Linux. Most of the programs in this book would work with all the compilers. Wherever there is a deviation I would point it out at that time. 


Assuming that you are using a Turbo C or Turbo C++ compiler here are the steps that you need to follow to compile and execute your first C program... 

(a) Start the compiler at C> prompt. The compiler (TC.EXE is usually present in C:\TC\BIN directory). 

(b) Select New from the File menu. 

(c) Type the program. 

(d) Save the program using F2 under a proper name (say Program1.c). 

(e) Use Ctrl + F9 to compile and execute the program. 

(f) Use Alt + F5 to view the output. 


Note that on compiling the program its machine language equivalent is stored as an EXE file (Program1.EXE) on the disk This file is called an executable file. If we copy this file to another machine we can execute it there without being required to recompile it. In fact the other machine need not even have a compiler to be able to execute the file. 

A word of caution! If you run this program in Turbo C++ compiler, you may get an error — “The function printf should have a prototype”. To get rid of this error, perform the following steps and then recompile the program. 

(a) Select ‘Options’ menu and then select ‘Compiler | C++ Options’. In the dialog box that pops up, select ‘CPP always’ in the ‘Use C++ Compiler’ options. 

(b) Again select ‘Options’ menu and then select ‘Environment | Editor’. Make sure that the default extension is ‘C’ rather than ‘CPP’. 

In the program discussed above we assumed the values of p, n and r to be 1000, 3 and 8.5. Every time we run the program we would get the same value for simple interest. If we want to calculate simple interest for some other set of values then we are required to make the relevant change in the program, and again compile and execute it. Thus the program is not general enough to calculate simple interest for any set of values without being required to make a change in the program. Moreover, if you distribute the EXE file of this program to somebody he would not even be able to make changes in the program Hence it is a goad practice to create a program that is general enough to work for any set of values. 

To make the program general, the program itself should ask the user to supply the values of p, n and r through the keyboard during execution| This can be achieved using a function called scanf( ). This function is a counter-part of the printf( ) function. printf( ) outputs the values to the screen whereas scanf( ) receives them from the keyboard. This is illustrated in the program given below. 

Code: >

/* Calculation of simple interest */

/* Author gekay Date 25/05/2005 */ 

# include <stdio.h> 

void main( ) 

{

int p,n; 

float r, si; 

printf("Enter values of p ,n ,r ");

scanf("%d %d %f ", &p , &n , &r);

si = p * n * r / 100 ;

printf ("%f", si)

}

The first printf) outputs the message ‘Enter values of p, n, r’ on the screen Here we have not used any expression in printf( ) which means that using expressions in printf( ) is optional. 

Note that the ampersand (&) before the variables in the scanf( ) function ts a must. & is an ‘Address of? operator. It gives the location number used by the vanable in memory. When we say &a, we are telling scanf( ) at which memory location should it store the value supplied by the user from the keyboard The detailed working of the & operator would be taken up in another blogs.

Note that a blank, a tab or a new line must separate the values supplicd to scanf( ) Note that a blank is creating using a spaceba, tab using the Tab key and new line using the Enter key This shown below. 


Ex.: The three values separated by blank 

        1000 5 15.5

Ex.:  The three values separated by tab

        1000 5 155 

Ex.: The three values separated by newline

        1000

         5

        155 

So much for the tips How about another program to give you 4 feet of things.......

Code : >

/* Just for fun. Author Bozo */

# include <stdio h> 

void main()

{

int  num; 

printf (“Enter a number" ) ; 

scant ( “%d", &num ) ; 

printf ("Now I am letting you on a secret...” ), 

paintf (“You have just entered the number %d", num );


Comments

Trending now

What is thyroid eye disease ? thyroid associated ophthalmopathy (TAO), thyroid orbitopathy, Graves’ orbitopathy or Graves’ ophthalmopathy (GO).

Who discovered electron ? How to discovered electron ? What is cathode ray discharge tube ? What is cathode ray and cathode ray particles ? | Inorganic chemistry | Chemistry.

Who discovered proton and neutron ? How to discovered proton and neutron ? What is canal ray? What is anode ray ? | Inorganic chemistry | chemistry.

Nature as depicted in the Kalidasa's literature

What is password attacks ? How many types of password attacks ? How to keep safe your self from hacking by password attacks ?|Computer science|ethical hacking

Monetary Policy of Malaysia

Architecture and sculptures of Assam