Running C Program on Window 8

In this tutorial we are going to see, how we can install DOSBox in order to run the traditional C program in the Latest Window 8 environment. In this tutorial we will be learning to run C Program on Window 8.

The DOSBox is x86 immulator which is used to run traditional 16/32 bit DOS applications in 64 bit environment those are incompatible with DOS applications.

Steps to run C Program on Window 8:

  1. Basically first step to run C Program on Window 8 is to get the DOSBox installer. Click here and download the DOSBox setup.
  2. Once you have setup of the DOSBox, you need to download the setup for TC. Get TC setup by clicking on this link. (Get TC Setup)
  3. Now you have all required installers with us, we can start installation now.
  4. Extract the TC.zip file in the C:\TC\
  5. Unzip TC

  6. Now unzip the DOSBox0.74-win32-installer.zip and run the installer file to install the DOSBox.
  7. After installation of the DOSBox open the DOSBox Application by double clicking on the DOSBox icon on the desktop.
  8. DOSBox icon

  9. You need to type following command in the Prompt -
  10. mount e c:\TC\

    C Program on Window 8 - Mount E Drive with DOSBox

  11. Now switch to E drive using the following command.
  12. E:
  13. Now hit following command to install the TC.
  14. install.exe

    C Program on Window 8 - installing the TC in DOSBox

  15. Press enter to continue
  16. C Program on Window 8 - TC Installer Window

  17. Now Select “E” drive by typing E and hit enter key.
  18. C Program on Window 8 - Select E drive

  19. Now keep the source path as it is. Again hit enter key.
  20. C Program on Window 8 - Selecting the path

  21. Now using down arrow key navigate to the “Start Installation” menu and hit enter key.
  22. starting installation

  23. After installation gets started you can see the below blue window like this -
  24. Installation started

  25. After the installation you will be prompted with this window then press any key to view the help file
  26. open help

  27. Now when you will be prompted with the help window, then press escape key to close that window in order to return to the DOSBox
  28. Thus we have successfully installed TC using DOSBox.

Running TC using DOSBOX :

  1. Now we need to open the DOSBox option file to run TC as default application when we launch the DOSBox
  2. DOSBox Option file

  3. Now select the DOSBox 0.74 Option menu by searching in sidebar pane in Window 8
  4. Now go to the end in the opened dosbox-0.74.conf file and add the below code in the file -
  5. mount e c:\tc\
    e:
    cd tc
    cd bin
    tc
    
  6. save the file and close it.
  7. Now click on the DOSBox icon on the homepage to launch the DOSBox, TC will gets opened as default application. Enjoy the flavor of the DOS in Window 8 environment.

In the next tutorial we will be going to see how to open and run c program using the dosbox.
More help : Dosbox Installation guide

C Language is Middle Level Language

Middle level language

Middle Level Language ?

C Programming bridges gap between traditional Machine Understandable Machine Level language and more conventional High level languages. User can Use C Language to do system programming for writing operating system as well as application programming.
[box]Middle Level Programming languages are closely related to Machine as well as Human Being.[/box]

Why C is Middle Level Language ?

  1. C Programming Supports Inline Assembly Language Programs .
  2. Using inline assembly language feature in C we can directly access system registers.
  3. C Programming is used to access memory directly using pointer.
  4. C Programming also Supports high Level Language Features.
  5. It is more User friendly as compare to Previous languages so C programming is Middle Level Language.
C Language is Middle Level Language

C Language is Middle Level Language

Tips : Middle Level Language

  1. Language is more Close to Machine
  2. Language is far from Human i,e human need to take more efforts to code
  3. We have to Write More Code to meet user requirement and It is Easy to create Machine Level Code using C Programming.

This Article may be useful for readers.

Middle Level Language Programming Concept

High level language

High level Language :

  1. First high-level programming languages were designed in the 1950s.
  2. High level Language is Human understandable Language.
  3. English is Common example of High Level Language.
  4. High level Language is Internal Machine Code Independent.
  5. High level Language is Program Oriented Language.
  6. High level Language is Developed for providing GUI Interface.

Middle Level Language Programming Concept

Explanation :

As you can see the above diagram, it clearly shows that HLL are more close to human and can be easily programmed as compare to lower level language.In HLL Language and Machine gap is more.

C Programming can be considered as High Level / Low Level -

  • In early 70’s , C Programming was considered as High Level language because it was capable of evaluating expressions,parenthesis recursive functions etc.
  • Nowadays C may be considered as “Low Level Language” by some programmer because it lacks a large runtime-system (no garbage collection, etc.)

Execution Models of HLL :

1. Interpreted :

  1. Interpreted languages are read and then executed directly, with no compilation stage.
  2. Program is read line by line and convert it into machine code, and executes it. [More Info : Interpreter]

2. Compiled :

Languages are transformed into an executable form before running There are two types of compilation:

2.1 Machine code generation

Some compilers compile source code directly into machine code. Machine code is generated by using compiler it is called as “truly compiled” languages.

2.2 Intermediate representations

Language is converted into middle level language and further optimized and reused.

3. Translated :

  1. A language may be translated into a lower-level programming language for which native code compilers are already widely available.
  2. The C programming language is a common target for such translators.

Some High Level Languages :

  1. Ada
  2. Algol
  3. LISP
  4. Pascal
  5. Prolog.
  6. Java
  7. C#

Low level language

We have already learnt the low level language features of c programming language and its applications. In this tutorial we will be learning what is exactly meaning of low level language.

What is Low level Language in Computer Science ?

  1. Machine understandable Language.
  2. Assembly is common high level language
  3. Internal machine code dependent
  4. Fast to run but slow to write & understand

What is Low Level Language ?

What is machine Level Language ?

  1. Machine code is the only language a microprocessor can process directly without a previous transformation.
  2. Currently, Programmers never write programs directly in machine code, because it requires attention to numerous details which a high-level language would handle automatically.
  3. Low Level Language requires memorizing or looking up numerical codes for every instruction that is used.
  4. For this reason, second generation programming languages provide one abstraction level on top of the machine code.

Recommended Article : Assembly language code in C program

Example

Below is a example function in 32-bit x86 machine code to calculate the nth Fibonacci number

8B542408 83FA0077 06B80000 0000C383
FA027706 B8010000 00C353BB 01000000
B9010000 008D0419 83FA0376 078BD98B
C84AEBF1 5BC3

Higher Level Languages and Middle Level languages are different than Low Level Language in many aspects.

Summary of lower level languages

Low level languages are Machine Understandable, difficult to write, requires more efforts to code and debug.

Single Line Vs Multi line Comment : Difference

Difference Between Single Line and Multi line Comment ?

Multi-line CommentSingle-line Comments
Starts with /* and ends with */Starts with //
All Words and Statements written between /* and */ are ignoredStatements after the symbol // upto the end of line are ignored
Comment ends when */ OccuresComment Ends whenever ENTER is Pressed and New Line Starts
e.g /* This is Multiline Comment */e.g // Single line Comment

Comments in C :

Below are some of the examples where we can use different kinds of comments.Single line comment and multiple line comments can be

Hiding Code using Comments :

Single Line Comments are useful where you need to comment or hide two-three words however multiple line comments are useful where you want to hide multiple lines of code.

/*
for(i=0;i<num;i++)
 {
 printf("\nEnter the Number : ");
 scanf("%d",&arr[i]);
 }
*/

i.e Suppose we want to hide multiple lines then instead of using single line comment before each line we can use multiple line comment.

for(i=0;i<num;i++)
 {
 printf("\nEnter the Number : ");
 scanf("%d",&arr[i]);
 // i++; 
 }

Rules of Writing Comments

Rules :
1 . Program Contain Any number of comments at any place

void main(/*Main Function*/)
{
int age; // Variable
printf("Enter Your Age : ");
scanf("%d",/*Type Age*/&age);
printf("Age is %d : ",/*Your age here*/age);
getch()
}

2 . Nested Comments are not allowed i.e Comment within Comment

/* This is /*Print Hello */ */
printf("Hello");

3 . Comments can be split over more than one line.

printf("Hello");    /* This  
                       is 
                       Comment */

4 . Comments are not Case-Sensitive.

printf("Hello");
    /* This is Comment */
    /* THIS IS COMMENT */

5 . Single line Comments Starts with ‘//’

printf("Hello");
    // This is Single Line Comment

C Multi Line Comment

In the previous chapter we have learnt about the the single line comment and in this tutorial we are going to learnt about the multiple line comments in c programming.

Multi Line Comment

  1. Multi line comment can be placed anywhere.
  2. Multi line comment starts with /*.
  3. Multi line comment ends with */.
  4. Any symbols written between '/*' and '*/' are ignored by Compiler.
  5. It can be split over multiple lines

C Program : C Multi Line Comment

#include<stdio.h>
void main()
{
printf("Hello");
/* Multi
       Line
  Comment 
*/
printf("By");
}

In the above code we have written the multiple line comment in c code. In the below code we have marked the part which is ignored by compiler when we use multi line comment in c programming.

#include<stdio.h>
void main()
{
printf("Hello");
/*--------------------------------------------
  ------------------Ignored by compiler-------
  --------------------------------------------
*/
printf("By");
}

In the upcoming tutorials we will be learning the different rules for writing comments

Different Ways of Using Multiple Line Comment :

Way 1 : Used for Program Title and Documentation

/****************************************
  * Title : Program Name *
  * Author: Author Name *
  ***************************************/

Multi line comment can be used to show the author related information while writing the documentation notes. It is necessary to write the documentation information of the program to organize the multiple c files in big project

Related article : How to write readable and eye-caching source code ?

Way 2 : Used for More detailed comment inside program

/* following line is used to get -
   1.Count of the Customer 
   2.It is going to Return Integer
*/
int var = getCount(str);

OR

int var = getCount(str); /* Used to count 
                               Number of Persons
                                  Present */
pritnf("count : %d",var);

When our source code have complex or important step then it is important to write the multi line comment which can provide the necessary information about the complex statement

C Single Line Comment

Single Line Comment

Comments are non-executable code used to provide documentation to programmer. Single Line Comment is used to comment out just Single Line in the Code. It is used to provide One Liner Description of line.

Some Importatnt Points :

  1. Single Line Comment Can be Placed Anywhere
  2. Single Line Comment Starts with ‘//’
  3. Any Symbols written after ‘//’ are ignored by Compiler
  4. Comment cannot hide statements written before ‘//’ and On the Successive new line

Live Example :

#include<stdio.h>
void main()
{
printf("Hello"); //Single Line Comment
printf("By");
}

Which Part is Ignored by Compiler ? [Shown by Asterisk]

#include<stdio.h>
void main()
{
printf("Hello"); // ********** Until Line Ends *****
printf("By");
}

Explanation :

  1. In the above code we have included Single Line Comment. Single Line Comment can be used anywhere in the code.
  2. Single Line Comment ignores the complete line from the position where it has been written.Therefor Single line comment is written usually after termination of statement.
  3. For Multiple Line Comment we have another approach.Learn More on Difference between Single Line and Multiple Line Comment.

Different Ways of Writing Singular Line Comment :

For Specifying Operation

#include<stdio.h>
int main()
{
int cvar=1,dvar=2;  // Declare Variables
int sum = 0;        // Declare Sum
sum = cvar + dvar;  // Compute Sum
printf("Sum : %d",sum);
return(0);
}

We can use this type of comment to specify the operation that we are performing or to specify the formula used.

Run c program using command prompt in window

Introduction :C Program can be run using Command Prompt .We can use MS-DOS to run c Program. Every window OS comes with inbuilt Command Prompt. So we are going to use this command prompt to run our c program.

Pre-requisite :

  1. Window’s Command Prompt
  2. Turbo C/C++ Compiler

Why we should run C Program using Command Prompt?

  1. We have Stored our C programs inside directories other than (C:/TC/bin) then we are unable to run c program.
  2. In order to run C Program we must copy C Program and paste it inside bin folder.
  3. This process is bit time consuming and complex.

Running C Program using Command Prompt :

  1. Create One Directory in D Drive (in my case my directory is “C Programs”)

  1. Now we must have Turbo C/C++ IDE installed in your system.( You may download it from here)
  2. After installing Turbo C/C++ IDE we have this directory Structure

  1. Now Right Click on My Computer Icon and Click on Properties

  1. Click on Environment Variable Button.

  1. Make entry of bin inside Path Variable.

  1. Make Entry of TC>bin inside Path Variable and Click on OK.
C:\TC\BIN
  1. Now Open Command Prompt by typing cmd inside “Run” Option.
  2. Go to Path Where you have Saved your C Programs.
Microsoft Windows [Version 6.1.2025]
Copyright (c) 2009 Microsoft Corporation.  All rights 
reserved.
C:\Users\Santoshi>D:
D:\>cd C Programs
D:\C Programs>
  1. Suppose we have Saved hello.c program inside “C Programs” folder. then type this command to Compile hello.c
D:\C Programs>tcc hello.c
Turbo C++ Version 3.00 Copyright (c) 1992 Borland 
hello.c:
Turbo Link  Version 5.0 Copyright (c) 1992 Borland 
        Available memory 4106832
  1. After typing “tcc command” we can compile C Program.
  2. Now its time to run C Program after Successful Compilation.Just Type Program name and Hit Enter you will get output on the console
D:\CPROGR~1>hello
Hello

Note :

Actually tcc.exe Command is located inside C:/TC/bin So we have make this entry inside path variable so that Command Prompt can find this command from that specified path.

Run C program in linux environment

How to Run C Program in Linux Environment ?

Step 1 : Open Any Text Editor in Linux .
Step 2 : Type this Following Snippet in Editor.

#include<stdio.h>
int main()
{
printf("Hello , Welcome to Linux Environment");
return(0);
}

Step 3 : Save this Program by .C extension. [Say above program as hello.c ]
Step 4 : Open Terminal.
Step 5 : Type this to Compile

cc hello.c

Step 6 : Type this to Run

./a.out

Step 7 :Hello , Welcome to Linux Environment” will be displayed on Screen.