Monday 20 February 2012

Executing C Program


Dear readers,
     After successfully learn the compiling C program and linking C program lessons. You are now ready to learn how to execute C program on your computer. 
SO FRIENDS LETS START LEARNING
  • Executing C program :-
                            The process of running the program on computer is called executing. The program must be loaded into memory for execution. This work is done by the Loader. Loader is a program that loads the executable file from disk into memory.
For Example :-
             In Windows environment, when the name of an executable file is double clicked. The Loader loads the file into the computer memory for execution on the CPU.
In TC Editor, you can compile and run the program by pressing the shortcut key Ctrl+F9 or by selecting Run command from Run menu of Turbo C IDE. The program is first compiled and then run on the computer.
                   When the program is run, the program's output  is printed on the screen but not to the IDE window. To see the program's output, select "User screen" command from the window menu, or press keyboard shortcut Alt + F5. You will see normal DOS screen with program output (if any).
      Some errors may occur during the execution of the program. These errors are called the execution errors. These errors may halt the system.

Linking C Program


Dear readers,
               In this post you will learn the method to link a C program....
SO FRIENDS LETS START LEARNING
  • Linking C program :-
               Linking is a process in which the object file produced by the compiler is linked to many other library files. This work is done by the Linker.
 The Linker is a program and is a part of compiler. After linking the object code to the libraries, an executable file with extension EXE is created.
For example :-
            If  source file name is "test.c", then executable file name will be "test.exe".
                      In Turbo C environment, program is linked as;
  • Select Link command from Compile menu on the menu bar.
 
In Turbo C IDE, compiling and linking can be performed together in one step. To do this, select Make command from Compile manu or press F9 key. The linker can also detect errors.
  • For Example :-
If the source code uses a library function that does bot exist, the linker generates an error. If there is any error in the source code, the Linker will not create the executable file.
 In this case, the errors are removed from the source code and source code is compiled again. The new object file is then linked to the libraries to create the executable file. The file directly dun on the computer.

Compiling C Program


Dear readers,
       In this lesson we tell you how to compile C Program ?....
SO FRIENDS LETS START LEARNING
  • Compiling C Program :-
                  You write the source code of the program by following rules of the programming language (i.e. C language).

     
 The source Code is not understandable by the computer. The source code must be translated into machine code before running on the computer. The process of translating source code into machine code is called compiling.
       The C compiler is used to translate the C program source code into the machine code. The translated code is called object code.
 when C compiler translates the source code, a new file created for object code with extension "obj". The first part of the name of object file is same as that of source file. 
For Example :-
           If source file name is "test.c", then object file name will be "test.obj".
                             To complete the C program source code into object code in Turbo C IDE, follow these steps.
  • Press Shortcut Alt+F9
  •                  OR
  • Select Compile command from compile of menu bar.
If there is no error in the source code, it will be translated to object code successfully. If there are errors in the source code, compiler will not compile the source code and will report about the errors in the source code. All errors must be removed from the source code before creating the object code of the source code. 

Sunday 19 February 2012

Creating, Editing and Saving C program

128 x 128 black c gif icon image
Dear Readers,
       In this lesson following topics are covered...
  • Creating C Program
  • Editing C Program
  • Saving C Program

SO FRIENDS LETS START OUR LESSON
               You can write, edit and save a C program in any text editor program. But Turbo C provides a complete IDE for this purpose. You can easily write, edit and save C program in TC editor.
  • Creating C Program :-

                  The process of writing a new C program by following the rules of C language is called creating a C program. To write a new C program, load the TC editor and type the source code of program.
  • Editing C Program :-
   
                    You can also make changes during writing new programs as well as in the exiting C program. Therefore, the process of writing, changing and revising the source code is called editing program.
  • Saving C Program :-
 
                        After writing or editing the source program, you should save it on the disk as text file with an extension " .c ". This process is called saving the program.
                         To save source code in TC editor, follow these steps.
  • Select Save command from file menu or press F2 key. A dialog box will appear. The default file name of source code is NONAME00.C
  •     Type the name of file such as "first.c" and press Enter key. You can also select a specific folder (or location). where you want to save the file. Turbo C editor automatically assigns the file extension as " .c "



Note:-
                                            You can also compiler and run C program in Turbo C IDE without saving it first but it is not a good practice. You must save the program before compiling and executing it. It is because sometimes your program may be hanged during execution and your source program code may be erased from the main memory.

Installing Turbo C


Dear Members,
          In this lesson we tell you How to install Turbo C Editor? and setting up directories ...
SO FRIENDS LETS START OUR LESSON
  •  Installing Turbo C :-
                          Turbo C compiler is commonly available on CD's. When you install the Turbo C compiler, the TC directory is created on the hard disk and various sub directories such as INCLUDE, and LIB etc. are created under TC.
                    INCLUDE :-         Contains the header files of C.
                         LIB :-                 Contains the library files of C.

                     When Turbo C is installed, the above mentioned directory structure is automatically created and their respective files are copied into them.
           The installing process of Turbo C is very easy. It provides "install" program used to install the Turbo C compiler. Simply, run the install program and follow the instructions such as ; the directory name and path where you want to install the system (Turbo C compiler). By default, directory name is TC on the root of drive C.
  • Setting Up Directories :-
By default, the source files, object files and executable files are stored in the current directory (or TC directory). You can set specific directory paths to store source files and output files (i.e. object and executable files).

             To set the directory path, follow these steps.
  • Select "Directories" from "options" menu of Turbo C editor, a window will appear as shown below.
 
  •                       Set the path of header files in the "include Directories" field such as " C:\TC\INCLUDE". 
  •                       Set the path of library files in the "Library Directories" field such as " C:\TC\LIB ".
  • In "Output Directory", the compiler stores the object files and linker stores the 'exe' files. Set the path for output files.
  • In "Source Directories", the source files are stored. Set the path for source files.

Sunday 12 February 2012

Turbo C Interface


Dear Visitors,
        In this post we give you knowledge about Turbo C Editor. Please note that Turbo C is a most common C language compiler. This lesson helps you to know about its interface its using and its functions....
SO FRIENDS LETS START OUR LESSON
  • Turbo C Editor :-
                           The interface of Turbo C is very simple. When IDE screen appears, the menu bar is activated. It contains various menus such as:
  • File :-
                       This menu contains group of commands used for saving program, operating existing program, printing source code of program, exiting from Turbo C editor etc.
  • Edit :-
                       This menu contains group of commands used for editing C program source code. The important editing commands are:-
Copy, Cut, Paste, Undo etc.
  • Search :-
                       This menu contains group of commands used for searching specific word as well as replacing it with another one.
  • Run :-
                      This menu contains group of commands used for running C program.
  • Compile :-
                      This menu contains group of commands used for compiling C program. 
  • Debug :-
                        This menu contains group of commands used for debugging C program.
  • Project :-
                         This menu contains group of commands used for opening, closing and creating projects.
  • Options :-
                          This menu contains group of commands used for configuring IDE of Turbo C and setting up directories etc.
  • Windows :-
                           This menu contains group of commands used for opening, closing various windows of IDE.
  • Help :-
                            This menu is used to get help about specific topic of C language, You can also get help by pressing  F1 key. Similarly to get help about a specific keyword or identifier of C, type a word, keep cursor on the word and press keyboard shortcut Ctrl + F1.

Friday 10 February 2012

TC Editor


Dear Members,
                 In this post you will learn about TC Editor and its uses...
SO FRIENDS LETS START LESSON
  • TC Editor :-
In addition to a compiler, Turbo C or TC provides a complete IDE to create, edit, save, compile and run C programs. It is called the TC Editor. The C compiler is linked with TC Editor. This type of editor is also called linkage editor.
                     TC editor also provides a powerful debugging feature. This means that it helps to detect and remove errors in the C program.
                              Once Turbo C compiler is installed. It is very easy to write,compile and execute C programs, Turbo C editor has an executable file "TC.EXE". By default, it is in "TC" directory in C drive. When the file is executed, the IDE of Turbo C editor is displayed on the screen along with development tools.
               To load Turbo C editor, follows these steps :-
  • Go to DOS prompt. By default, it will appear as:

C:\Windows>
  • Change the directory to TC by applying command;

C:\Windows> CD\TC  [press Enter Key]
  • Type TC and press Enter Key. The turbo C editor is started and IDE appears on the screen as shown below.
Note :-
             Today, in most computers Turbo C++ compiler is installed. If Turbo C++ compiler is installed in your computer, then the path of TC.EXE is: 
C:\TC\BIN

Thursday 9 February 2012

C compiler & IDE


Dear Members,
       In this post we will tell you about the Compiler of C Language and its importance also tell you about IDE...
SO FRIENDS LETS START OUR LESSON
  • Compiler of C Language :-
Every High Level language has its own translator program. It is used to translate the source code into machine code. C language also has its own translator program called C compiler.
 You must install C compiler into your Computer for compiling the C program. Many C compilers are available. The Most popular and commonly used C compiler is Turbo C.
Note :-
         "You can also translate C program with C++ compiler."
  • IDE :-
 

IDE
stands for Integrated Development Environment. The environment in which a computer program is written, compiled, executed, tested and debugged is called Integrated Development Environment.

C Program Errors


Dear Members,
         "Today we share with you an important lesson"
In this lesson we tell you about those errors which can be made by every beginner programmer at that time when they write C program. 
           In this post we tell you that what happen if you made these mistakes during writing C program
SO FRIENDS LETS START LESSON
  • ERROR No 1).
  • Leave  #include<stdio.h> :-

                                  #include<stdio.h>

                           int main(void)
{
                                                                            printf("My first Program in C");
}
                   A header file must be included at the beginning of the program. If its functions are to be used in the program. In the above program, the printf() function is used to print the message. It is part of header file "stdio.h". When you leave out the #include<stdio.h> line from the program given above, the C compiler displays an error message as shown below:
''Function 'printf' should have a prototype''
  • ERROR No 2).
  • Leave Semicolon :-
 
Each statement in C ends with a semicolon (;). If you leave out the semicolon at the end of the printf() statement, an error message occurs as shown below.
Statement Missing ;

             Hope this lesson is really helpful for you. If you like this lesson don't forget to make a comment on it.
Thanks for your time.

C program Statements


Dear Members,
        Today we will discuss about C program statements and also give you some examples....
SO FRIEND LETS START OUR LESSON
  • C program Statements:-
A program statement is a fundamental unit of any programming language. It is an instruction for the computer to do something. The set of statements of C program are written under the main() function (or any user defined function) between curly brackets i.e {     }. Typically, in C program, the library functions are called for execution in the main body of the program.
For Example:-
                    The printf() function is used to print a message or output of the program. Every statement of C program must be terminated with semicolon (;). It is called statement terminator. If statement terminator (;) is missing at the end of any statement, then the following error message will be reported by C compiler during compiling process.
Statement Missing
         C language is a case sensitive language. Each statement of C program is normally written in lowercase letters. However, variable names or user-defined function names with uppercase letters can be used in C program.
                             C program is written below to clear the computer screen and to print a message on the screen.
                                   #include<stdio.h>
                                    #include<conio.h>
            main()
{
                              clrscr();
                                                       printf("Welcome");
}

In the above program, two statements are written in the body of main() function. Each statement ends with semicolon ( ; ).

Tuesday 7 February 2012

Main() Function

Dear Visitors,
           In this lesson you will learn about main() function of a program and also their uses in C....
SO FRIENDS LETS START OUR LESSON
  • Main() Function:-
                              The main() function indicates the beginning of the actual C program. It is the point at which execution of program is started. When a C program is executed, the execution control goes directly to the main() function.
                Every C program must have the main() function. The main() function comes after the preprocessor directives.
  •       The general syntax of main() function is:
                       void main(void)
{
                                           Body of main() function
}
In the above syntax:
1). The keyword 'void' is used before main() function. It indicates the data type of the value that is returned by the main() function. By definition, a function may accept one or more parameters and returns a single value.
          The program is executed with in an operating system (e.g, DOS). At the end of program execution, the main() function can return a value to the operating system. The 'void' means that program will not return any value to the operating system after its execution.
          You can use "int" in place of 'void'. In this case, program will return an integer value. The operating system uses this value to determine whether the program is executed successfully or not.
2). The keyword 'void' used within brackets after the main() function indicates that program takes no parameters when program is executed from command line (i.e. DOS prompt).
       Note: 
                     The use of 'void' or 'int' before the main() function are the main body of the main() function are optional.
3). The statements written under the main() function are the main body of the main() function. The body of the main() function is enclosed in braces ( or curly brackets { } ). These braces are called delimiters. The left brace indicates the start of the body of the function. whereas the matching right brace indicates the end of the body of the function.

Sunday 5 February 2012

Header Files

Dear Visitors,
            In this post you will learn about the 'Header Files' and their uses in C program.....


SO FRIENDS LETS START OUR LESSON
  • Header Files:-
The header files contain the declarations or information of standard library functions. These functions are called in the main body of the program to perform different tasks. The extension of a header file is ".h".
                In C language, there are many header files. Each header file contains information (or declarations) for a particular group of functions. 
For Example:-
  The header file "math.h" contains declarations of mathematical functions available in C.
         A header file must be included at the beginning of the program, it its functions are to be used in the program. A program may contain many header files.
 The "include" directive is used to include the header file into the program. The name of header file is written between angle brackets < > or in double quotes.
      The general syntax to include a header file at the beginning of C program is:
#include<name of header file>
For Example:-
                           To include header file 'stdio.h' and 'conio.h' in the program the statements (preprocessor directives) are written as:-
#include<stdio.h>
#include<conio.h>
                         In most C programs, header file "stdio.h" is used. The word ''stdio" stands for standard input or output. This file contains the declarations of standard input and output functions. These functions are used to get input and to print output. Similarly, ''conio.h" header file is included to use its functions "clrscr()". The "clrscr()" function is used to clear the screen of monitor.

Define Directive

Dear Visitors,
          In earlier post we tell you about the include directive.....
Today we are going to share with you knowledge about define directive.


SO FRIENDS LETS START OUR LESSON
  • The 'define' directive:- 
The 'define' directive is another important preprocessor directive. It is used to define a constant known as constant macro. A constant macro is an identifier, which is assigned a particular constant value. The value of identifier remains constant during the execution of program. Its general syntax is:
#include identifier expression  
Where
  • Identifier:-
                             Specifies the identifier (or macro name) to which the constant value is to be assigned.
  • Expression:-
                            Specified the constant value that is to be assigned to the identifier. It may be a constant value, a string or an arithmetic expression.
          For Example:-
In the following statements, PI has been assigned value 3.141593 and 'city' is assigned value Islamabad.
#define PI 3.141593
   #define city Islamabad

Saturday 4 February 2012

Include Directive

 
Dear Visitors,
          As you learn in our previous post that the most important preprocessor Directives are:

  • Include directive
  • define directive
Today we will share with you knowledge related to include directive......


SO FRIENDS LETS START OUR LESSON
  • The 'include' Directive:-
The 'include' directive is used to include the specified header file in the program. It means that this preprocessor directive tells the preprocessor to insert the definitions of standard functions (used in the program) into C program from a standard library.
               The general syntax of "include" directive to include standard header file is:
#include<name of header file>
For Example:
To include header file "stdio.h" in the program, the preprocessor directive is written as:
#include<stdio.h>
The above preprocessor directive tells the compiler to include header file "stdio.h". This header file contains the information about standard input and output functions. The scan() and printf() functions are the most commonly used input and output functions.

Friday 3 February 2012

Preprocessor Directives

Dear Visitors,
      In our earlier post we give you knowledge about the Basic Structure of C program. Today we are going to share with you knowledge about the Preprocessor Directives and also tell you its importance in C program.


SO FRIENDS LETS START OUR LESSON
  • Preprocessor Directives:-
The commands that give instructions to the C compiler are called preprocessor directives. They are given at the beginning of the source code. The preprocessor directives are also known as compiler directives.
                            A preprocessor directive begins with a # sign followed by a word "include" or "define". It is an instruction or directive that tells the C compiler to take action(s) before compiling the source code.
                             The part of the C compiler that takes action on the preprocessor directives is called preprocessor. It does some processing before the actual compilation process starts.
  • For Example:-
                                    "include" directives is used to include header file in the C program. This preprocessor directive includes the specified header file into the source code before compiling. It must be noted that preprocessor directive does not end with semicolon (;).
The most important preprocessor directives are:
  • include directive
  • define directive

Basic Structure of C Program

Dear Visitors,
           In this post you learn about the Basic Structure of C Program.....


SO FRIENDS LETS START OUT LESSON

  • Basic Structure of C Program:-
"The format or way according to which a computer program is written is called the structure of the program". The program structure of different programming languages is different. C is a structured programming language. It provides a well defined way of writing programs.
The basic structure of C program consists of the following main parts.

1). Preprocessor Directives
2). The main() Function
3). C Statement
                       
              To explain the structure of C program, a program example that prints a message "My first program in C." is given below.

              #include<stdio.h>
              main()
 {     
              printf("My first program in C");
 }


      In the above program:
1). The header file "stdio.h" is used at the beginning of program. This file contains the declarations (or information) of standard input and output functions used to get input and to print output. This header file is included because "printf()" function is used in the main body of program to print message "My first program in C".
                             The lines beginning with # sign indicates that this is an instruction for a C compiler are called Preprocessor directives. The #include<stdio.h> is an example of Preprocessor directive.
2). The "main()" function comes after the preprocessor directives. It indicates the beginning of the actual C program. It is the point at which execution of program is started. 
3). The set of statements (or instructions) of C program are written under the "main()" function between curly brackets i.e { }. Each statement of C program ends with semicolon ( ; ).

Thursday 2 February 2012

C Preferable Language

Dear Visitors,
        In this post we will tell you the two reasons why it would be preferable to write program in C rather than in machine language......


SO FRIENDS LETS START OUR LESSON

Due to these two reasons programmer prefer C Language to write program rather than machine language.

1). Easy to Learn and Use:-  
                        C language is high level language. It is very easy to learn and to write program. The errors in the C program can easily be detected and removed. It is also easy to modify the C program.
                                             On the other hand, machine language is low level language. The program is written as a combination of 0s and 1s. Machine language is not easy to learn and to write program. The errors in the program are difficult to detect and to remove. It is also difficult to modify  the program.

2). Machine Independent:-
                          Program written in C language is machine independent. It means that a program written in one type of Computer system can be executed on another different type of Computer.
    On the other hand, a program written in machine language is machine dependent. Every type of Computer has its own set of rules for writing program in machine language. Program written on one type of computer system cannot run on different type of Computer.