In this document we will see how we can compile and execute C program in Linux and Windows.The document also contains a list of C compilers available.
We will see how to compile using Visual C++ 2008 Express Edition, Turbo C++, wxDev-C++ in Windows. For Linux and Unix operating systems, we will be using GNU Gcc to compile C program. Both of these are free.
Install, compile and execute C program with Visual C++ 2008 Express Edition with SP1 in Windows
Download and install
To download, point your browser to http://www.microsoft.com/visualstudio/en-us/products/2008-editions/express and select Language and click on Free Download. After you complete download, run the executable file, it will ask you to select whether you want to install some other optional products, uncheck those options so that you can install only the product required. The installation process will start downloading other files from the Microsoft site and depending upon your connection speed it will take a while to complete the installation.
Once the installation is complete, in Windows 7, start the Visual Studio 2008 Command Prompt from All Programs > Microsoft Visual C++ 2008 Express Edition > Visual Studio Tools > Visual Studio 2008 Command Prompt.
Write, compile and execute your first program
Step 1 : type notepad demo.c (you can replace the filename with your own) and press Enter, when asked if you want to create a new file, say yes.
Step 2 : type the following code and click File > Save . When asked where to save the file, select the location suitable.
Step 3 : Type cl sample.c and press enter now. This will compile the program to create an executable file (.exe).
Step 4 : Now simply type the name of the file sample and enter. That will show you the output.
Install, compile and execute C program with Turbo C++ in Windows
Obtain and install
Turbo C++ is very popular C compiler and IDE. The problem is, Borland, the creator organization of the compiler and IDE does not provide any option to download the compiler and IDE. But if you google with "turbo c++ download", you will get plenty of sites to download the compiler and IDE. There are three files to download - TC.exe, tc.r00 and tc.r01. After downloading, run TC.exe file it will create a folder TC at the end the installation process. To run turbo C++, enter bin directory within TC and look for tc.exe. Double click the tc.exe file and turbo C++ IDE will open.
Run Turbo C++ in full screen in Windows 7
Those who are running Turbo C++ is Windows 7, when the IDE is opened, click on "Ignore" in the popup window saying that it does not support full screen mode. Now, click on the top left corner of the Turbo C++ window and select "Properties" . Select "Font" tab and change the font to "Lucidia Console" from default "Raster fonts". Also change the font size to "28". Now select "Layout" tab and set "width" as 80 and "Height" as 25 under "Screen Buffer Size". Under "Window Size", change "Width" as 60 and "Height" as 25. Under "Window Position", set value of "Left" and "Top" both as -4. Make sure "Left System Position Window" is unchecked. Click "Ok" to close the properties window. Now you can see the Turbo C++ IDE in full screen.
Write, Compile and Run C program
Open a new file from File > New in the Turbo C++ IDE. Write a small program in the IDE.
Now go to File > Save As and save the program with filename of your choice (make sure extension of the filename is .c).
Click on Options and go to Directories. Click on Directories and set Output Directory as you want and Source Directory as where you have saved the C program file.
Now go to compile and click on Compile. And then Click on Run. You will see the out put of your C program.
Write, Compile and Run C program using wxDev-C++ in windows
wxDev-C++ is an easy to use IDE which you may opt for to write C Program. You may download the installer from wxdsgn.sourceforge.net. We found it working perfect on Windows 7 and Windows XP. It also installs MinGW along with and you don't need to set any environment variables. The default compiler for this IDE is gcc.
After downloading the installer, run the exe file by double clicking on it and an installation wizard will guide you to install. Once you finish installation, you start it from Programs and first time when you run it, it takes a while for parsing header files. The IDe window looks like following:
You may start programming by clicking on File > New > Source File in the window. Note that while saving the file, you must select file type as C as this IDE supports C++ also.
You may use F9 or as shown below to Compile and Run program.
When compilation is done, it opens a new window to show you output.
If you have errors, it shows you in the pane below like following.
Though slightly dated, we find wxDev-C++ an excellent IDE for programming C. You may try it if you are using Windows.
Install, compile and execute C program in Linux
Most of the time, when you are installing Linux, GNU Gcc compiler is already installed. If not, run the following command (our system is Ubuntu Linux) :
If C compiler is already installed, it will show you a message like above. If not, it will install all the necessary packages.
Now open a text editor and write a small C program like following and save it as demo.c :
printf("Welcome to C Programming");
Now run the command as shown below to compile and execute the file :
This how you can install GNU Gcc compiler, write a C program and run it under Linux.
List of the C Compilers
Following table is a list of the C compilers available. This is not a complete list but this will give you a fair idea about various C compilers, which OS / Platform they support and whether it has a programming environment.
|Compiler||Author||Operating System||IDE?||License type|
|AMPC||Axiomatic Solutions Sdn Bhd||Windows,Unix & Other||Yes||Proprietary|
|Amsterdam Compiler Kit||Andrew Tanenbaum and Ceriel Jacobs||Unix & Other||No||BSD|
|CCS C Compiler||CCS, Inc.||Windows,Unix & Other||Yes||Proprietary|
|Clang||Low Level Virtual Machine||Windows,Unix & Other||No||BSD|
|DMS Software Reengineering Toolkit||Semantic Designs||Windows,Unix & Other||No||Proprietary|
|GCC C||GNU Project||Windows,Unix,IBM mainframe, AmigaOS, VAX/VMS, RTEMS||No||GPL|
|RCC (RCOR C Compiler)||Rodrigo Caetano (rcor)||Windows,Unix||No||GPL|
|Interactive C||KISS Institute for Practical Robotics||Wi ndows,Unix, Mac, Linux, IRIX, Solaris, SunOS||No||Freeware|
|LabWindows/CVI||National Instruments||Windows,Unix & Other||Yes||Proprietary|
|lcc||Chris Fraser and David Hanson||Windows,Unix & Other||Windows only||Freeware (source code available for non-commercial use)|
|Mark Williams C||Mark Williams Company||Windows,Other||Yes||Proprietary|
|Open64||SGI Google HP Intel Nvidia PathScale Tsinghua University and others||Unix,Other||No||GPL|
|Pelles C||Pelle Orinius||Windows||Yes||Freeware|
|PGCC||The Portland Group||Windows,Unix,Other— Mac OS X||Yes — Visual Studio on Windows||Proprietary|
|Portable C Compiler||Anders Magnusson and others||Windows,Unix,Other||No||BSD|
|Power C||Mix Software||Other||No||Proprietary|
|SAS/C||SAS Institute||Windows,Unix,Other-IBM mainframe, AmigaOS, 68K, 88K, Unix||Yes||Proprietary|
|Tiny C Compiler||Fabrice Bellard||Windows,Unix||No||LGPL|
|Turbo C||Embarcadero||Other||No||Proprietary - V 2.01 freely available|
|CCS C Compiler||CCS, Inc.||Windows,Unix,Other||Yes||Proprietary|
|MikroC Compiler||MikroElektronika, Inc.||Windows,Unix,Other||Yes||Proprietary|
|ups debugger (includes C interpreter)||Tom Hughes, Ian Edwards, and others||Unix,Other-Solaris, SunOS||Yes||GPL|
|VBCC||Dr. Volker Barthelmann||Windows,Unix,Other||No||Freeware (source code available, modification not allowed)|