12.11 – How to create a project in Turbo C

by subbu on December 24, 2013

In the previous session, we have learned that, it is a better programming practice to divide different sections of program into different files and linking together to prepare final build.
One way of doing is “external linkage” through tcc, which we have discoursed in the previous session.
Now, we will discourse another way of doing it using Turbo C IDE

What is C Project?

Project is actually not a program. It is a file that contains information regarding to different files to be included and linked while compiling to make a build (executable file).
While creating a project file, we need to select different files. So that, the compiler can prepare build by using these files while compiling.

How to create a project in Turbo C

A new project is opened with any name but, with .prg extension. Different files are added to the project one by one. As a final step project is build so that, an executable file is created to the total project. It can be used as an application on any computer (of same platform)

Step 1: Open a new project by selecting Project (Alt+P), Open Project(O). Give a name to the project with .prg extension (strong.prg).

New project in Turbo C IDE

Step 2: Create and save the files with .c extension and add one by one to the project

Select File (Alt+F), New (N)
Type the contents of file

/* first.c */
long factorial(int n)
{
long f;
int i;
for(f=0,i=1;i<=n;i++)
   f=f*i;
return f;
}

Save the file by selecting File (Alt+F), Save (S)  [first.c]

Adding a file to the Turbo C project

Set the focus to the project explorer in IDE by just clicking on it
Add the file [first.c] to project by selecting Project (Alt+P), Add item (A), Name: First.c

Adding item to the project

Select Add, Done

Selecting file to the project
Continue the same process with all other files

Adding second.c to the project

Select File (Alt+F), New (N)
Type the contents of file

/* second.c */
int isStrong(int n)
{
int temp;
long s;
for(temp=n,s=0;n!=0;n=n/10)
   s=s+factorial(n%10);
return ((s==temp)?1:0);
}

Save the file by selecting File (Alt+F), Save (S)  [second.c] Set the focus to the project explorer in IDE by just clicking on it
Add the file [second.c] to project by selecting Project (Alt+P), Add item (A), Name: second.c
Select Add, Done

Adding main.c to the project

Select File (Alt+F), New (N)
Type the contents of file

/*  main.c   */
#include<stdio.h>
int main()
{
int n,i;
printf("Enter the limit:");
scanf("%d",&n);
for(i=1;i<=n;i++)
 if(isStrong(i))
  printf("\n%d",i);
getch();
return 0;
}

Save the file by selecting File (Alt+F), Save (S)  [main.c] Set the focus to the project explorer in IDE by just clicking on it
Add the file [main.c] to project by selecting Project (Alt+P), Add item (A), Name: main.c
Select Add, Done

Step 3: Create the build by selecting Compile (Alt+C), Build All (B)

This option translates all the .c files into their equivalent .obj files, links together and generates build as an executable file with the project name.

Building the project

Step 4: Execute the program either by using ctrl+F9 or by double click on executable file.

Executable file of project is generally created in output folder of Turbo C as set in Options – Directories (c:\tc\works in author’s machine)

Double click on STRONG.exe to execute in windows mode

Running executable file

Previous post:

Next post: