12.21 – Creating executable file in Turbo C

by subbu on January 3, 2014

Executable file is the result of linker in the build process, saved with .exe file extension in case of Turbo C and MinGW gcc compiler, .out in case of Linux gcc compiler. It is the machine code that actually interacts with the machine.

Creating executable file using Turbo C

Method 1:
In case of a normal C program with a single file, save the program with any name but, with .c extension and press (Compile and link) F9. It will generate and save an executable file in the output folder as set in the Options – Directories

  • Open the Turbo C IDE
  • Select File (Alt+F), New (N)
  • Type the program
#include<stdio.h>
int main()
{
 int a,b,c;
 printf("Enter two numbers:\n");
 scanf("%d%d",&a,&b);
 c=a+b;
 printf("Sum of two numbers %d",c);
 getch();
 return 0;
}
  • Save the program by selecting File (Alt+F), Save (S) or F2
  • Save File name as: add.c

Saving a file Turbo C

Press F9 to compile and generate executable file

Creating executable file Turbo C

Now the executable file is created under the output directory as set in the Options – Directories. On author’s machine output directory is (c:\tc\works)

Executable file in windows

How to execute an executable file?

Executable file can be executed in two ways that are

1) By typing the name of the executable file in the command prompt

Executing at command prompt

2) By double click on application (executable file) in windows mode

Executing a file at command prompt

Method 2:

We can create an executable file by using Turbo C compiler (tcc) at command prompt

Note: Before going further, make sure that the path is set to c:\tc\bin as explained in the previous session 1.6 How to execute a C program in command prompt using Turbo C. So that, the tcc can be accessed from any where.

Setting path to TC

Create or change to any working folder (d:\fox)

Navigation:

  • Go to the DOS shell by selecting start – run – type cmd – open
  • Change to d:
  • Create a folder fox using the command md (Making directory)
  • Change to fox folder using cd (Changing Directory)
c:\...\...>d:
d:\>md fox
d:\>cd fox
d:\fox>

Type the program in the text editor and save with .c extension

d:\fox>edit add.c
#include<stdio.h>
int main()
{
 int a,b,c;
 printf("Enter two numbers:\n");
 scanf("%d%d",&a,&b);
 c=a+b;
 printf("Sum of two numbers %d",c);
 getch();
 return 0;
}
  • Select File (Alt+F), Save (S) to save the program
  • Select File (Alt+F), Exit (X)
  • Compile the program using Turbo C compiler (tcc), it will generate add.exe
d:\fox>tcc add.c

The executable file generated by the Turbo C compiler (tcc) can be executed in two ways that are

1) By typing the name of executable file at command prompt

executing from command prompt

2) By double click on executable file in windows mode

Executing a program in windows1

Previous post:

Next post: