Freelance Writing Jobs | Today's Articles | Sign In

 

Borland C Compiler Setup

MacOS, Windows, Linux installations, settings, and tutorial.

Mar 24, 2006 Guy Lecky-Thompson

Tutorial to help install the free Borland C compiler, get it up and running, and write a simple command line application.

Borland C Tutorial - Lesson 1

In this Borland C tutorial lesson we shall learn how to check that the Borland C compiler is correctly installed, and take our first steps with the C language, using the 'Hello World' application in the time honoured tradition of all programming tutorials.

We are using the free Borland C compiler because it is powerful, flexible, and allows us to create software for both command line and GUI (Windows) applications.

Of course, the first thing that you will need to do is download the Borland C compiler (explained in the Free Programming Tools article, and install it following the instructions received during the download process.

Before we continue, we should point out that only the C language tutorial part of this free C tutorial is valid for MacOS users, since it is targeted towards the free Borland C compiler available for Windows and Linux.

Checking your installation

The first thing that we need to do is ensure that your free Borland C environment is correctly installed. To do this, call up a command prompt, and type 'make'.

The Borland C environment should produce a message along the lines of:

MAKE Version 5.2 Copyright (c) 1987, 2000 Borland

If an error message appears such as 'make is not recognised as an internal or external command ...', then the Borland C environment has not been set up correctly. Linux users will know how to fix this, but on the Windows operating system family, it is a little less straightforward.

Typing 'path' will reveal that the install paths for your Borland C compiler have not been added to the system variables. Specifically, the 'bcc55\bin' folder needs to be added (mine is c:\borland\bcc55\bin') to the environment string.

Open the Control Panel (Start-Settings, Control Panel on post-Windows 95 machines) and find the System Properties entry. Double-clicking it brings up a dialog box containing a variety of tabs, among them 'Advanced'. Once this is selected the Environment Variables button can be clicked.

Finally, in the resulting dialog box, in the System Variables list box, locate the 'Path' variable, click 'Edit', and type your path (:\\bcc55\bin), not forgetting to append a semi-colon (;).

Checking again via the command prompt, we can now see that typing 'make' does what we would expect.

C Tutorial - Hello World!

With the preparation out of the way, we can now write our first application - called Hello World. Using your text editor of choice, type in the following:

#include // Using the C I/O Libraries
void main ( void ) // The 'entry point' to the program
{
// Display text, and add a linefeed
printf("Hello World!\n");
}

The above may seem simple, but there are few items to take note of:

  • #include : used to specify what external functions we need to make use of, i.e. those that we do not define here, and are provided by Borland C;
  • void main ( void ) : the entry point function, main, that returns nothing (void) and takes no parameters ( (void) );
  • printf() : used to print to the screen in a formatted way.

All the work is done inside the main function; and must be contained within braces ('}'). Useful programs, that output to the screen, will usually #include the stdio.h functions.

Save your program in a suitable text file (HelloWorld.c - note the .c extension), and turn it into a command line application by:

  1. Open a Command Prompt
  2. Navigate to the place you saved your HelloWorld.c file
  3. Type 'bcc32 HelloWorld.c'

Possible problems can be solved in one of two ways - trial and error, or using the Computer Programming discussions below to ask specific questions. The most usual is when the file has been named HelloWord.c.txt by the text editor, leading to:

Error 2194 : Could not find the file 'HelloWorld.c'

Renaming the file (rename HelloWorld.c.txt HelloWorld.c) will help in this case.

Questions

To help you get the most out of this Borland C tutorial, here are a few questions to ponder before reading Lesson 2:

  1. How would you make this program print a second line?
  2. How would you make this program print out 10 lines?
  3. ...or 100? Indefinitely?

(Hint : for that last one, if you're still using cut'n'paste, it's not the right answer!)

Answers via the mailing list, as well as an advance copy of the Lessons, as they arrive.

Continue to Lesson 2 : Loops..

The copyright of the article Borland C Compiler Setup in Computer Programming is owned by Guy Lecky-Thompson. Permission to republish Borland C Compiler Setup in print or online must be granted by the author in writing.
What do you think about this article?

NOTE: Because you are not a Suite101 member, your comment will be moderated before it is viewable.
post your comment
What is 1+6?

Comments

Jan 3, 2009 4:20 PM
Guest :
I have reproduced the code above precisely as a .c file and tried to compile it with the bcc32 compiler, but it keeps returning "Error E2046 HelloWorld.c 1: Bad file name format in include directive" followed by "Warning W8065 HelloWorld.c 5: Call to function 'printf' with no prototype in function main."

These messages persist even if I change it to #include <iostream.h> or #include <stdio.h> -- or even if I reference both of those libraries. I have tried referencing them both with and without the .h file extension specified.

A little help?
1 Comment:
;