C is one of the most powerful programming languages and it’s suitable for a wide variety of uses. You can compile C code with a number of different C and C++ compilers. The RAD Studio and C++ Builder IDEs are extremely powerful development tools for those who want to develop C and C++ applications of all types. In this post, we have ‘Hello World’ example and we have included an example that shows how to convert int to string C example and how to convert int to string C++ example too.
Today, actually in this year, we have many great selections of free C++ IDE and professional C++ IDE. Tools like C++ Builder CE, Dev-C++, and even the BCC32 command line compiler. Although C++ Builder’s primary purpose is to be the best available C++ IDE which helps developers be at their most efficient and effective possible selves it is also quite capable of editing and compiling most C code thanks to C and C++ having a shared lineage. The latest version RAD Studio 11.2 is announced with many new features.
Table of Contents
How to run a program in C with a free C++ IDE?
You can edit and run C code using C++ Builder. The C++ Builder system is a modern powerful C++ IDE. It has C and C++ compilers allowing you to carry out any variety of professional quality development.
C++ Builder has a free C++ Builder Community Edition. There is also a paid C++ Builder Professional / Architect / Enterprise version too.
1. Download the free C++ Builder Community Edition and install it.
2. In C++ Builder, create a new console application from the File->New->Console Application – C++ Builder menu . Chose C Language as a Source Type and Target Framework as None from the next window and press OK. ,
If you are new to programming, here is a quick introduction to create a simple C Program. C programs are simple text files, which means you can use any editor to edit these kinds of programs, but a proper C++ IDE has much more features.
How to develop and run a program in C?
When you start coding, first of all, you should include libraries that you wish to use. The C language has many libraries and each of them has commands or functions for specific tasks. For example, the stdio
library has standard input and output functions to read from files and similar sources. The signatures for these functions are declared in the stdio.h
header. Generally, for beginners, the stdio.h
header is enough to enable you to create simple apps. We can include this library header as below,
1 |
#include <stdio.h> |
Second, you should add a main
procedure. This is the main part of the program – hence the name – and it is executed first. In the simplest sense, all other parts of your program are launched from the main section either directly or indirectly. Things get a little more complicated than that once you start to write more complex programs but for now you can think of the main
section as the ‘main loop’ where things begin to happen in your program code.
1 2 3 4 |
int main() { } |
How to run a ‘Hello World’ example program in C?
After that you should write your lines of program code into this procedure, between the { and } brackets. If you are a beginner, “Hello World” examples are good to understand how the basic feature of a particular programming language works. It is also a good way to understand how to edit text, how the syntax (the rules) of the language work, how to compile and link, how to debug and execute, and how to deploy or release. This full example below is a “Hello World” C example that can be run with C++ Builder.
1 2 3 4 5 6 7 8 9 |
#include <stdio.h> int main() { printf("Hello World"); getchar(); return 0; } |
In C and C++, after every command you use you should put a semicolon “;”. In this example above we print a text with printf()
function and then we wait to get a character input (key press) with getchar();
functions, then we exit and return 0;
which means our main app has run successfully and exits.
In this example above we define the main()
function as an integer (int) function, that means we should return a integer value. Here, we print a text with printf()
function and then we wait to get a character input (key press) with getchar();
function, sometimes this is necessary to see results when running it. Then we exit and return 0;
which means our main app successfully ran and exited.
In C++ Builder you can simply press Run Button (without debugging or with debugging) or F9 key to compile and run your code, or you can use Run Menu to compile and run too.
How to run a ‘convert int to string’ example program in C?
You can improve our code with some commands from the C language. For example, we can use the sprintf() function to convert int to string in C and C++ apps as below,
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
#include <stdio.h> int main() { int x = 2023; char str[64]; sprintf( str, "%d", x ); // print x integer to str string printf( str ); getchar(); return 0; } |
In C++ Builder you can simply press Run Button (without debugging or with debugging) or F9 key to compile and run your code, or you can use Run Menu to compile and run too.
In this example above, sprintf()
is a very powerful function. You can also use itoa()
function to convert int to an array string. For example,
1 2 3 |
int x = 2023; char str[64]; itoa( x, str, 16); // convert integer to ascii string |
In C++ Builder, we can use Strings instead of array strings. As a ‘modern’ way still there is a Printf()
method that can be used for the Strings which are also UnicodeStrings.
1 2 3 |
int x = 2023; String str; // Unicode String in C++ Builder str.Printf( "%d" , x ); // print integer to Unicode String |
How to compile and run a saved program in C on a terminal?
If you want to run this program in Console, then execute the RAD Studio Command Prompt from the Windows menu in Windows. This will open a Command Console (Terminal) with RAD Studio / C++ Builder configs. After this step, in Terminal, go to folder of your C file and type bcc32 and your file name. For example, you can compile your app as below,
1 |
D:\MyApp> bcc32 myapp.c |
To run your compiled app you can type compiled excitable file name which has .exe extension of you C file. For example, to run compiled myapp.c
file write its executable output as below,
1 |
D:\MyApp> myapp.exe |
Note that you can also develop GUI based VCL or FMX C++ apps by using your C code in your apps too. C++ compilers are generally compatible with most of the C code and libraries.
How to compile and run a program in C professionally with a C++ IDE?
Although the free C++ Builder Community Edition is extremely powerful it is intended for students, beginners, and startups. If you are a regular business or do not qualify for the free community edition then you can download a free trial of the very latest full RAD Studio C++ Builder version.
C++ Builder is the easiest and fastest C and C++ IDE for building simple or professional applications on the Windows, MacOS, iOS & Android operating systems. It is also easy for beginners to learn with its wide range of samples, tutorials, help files, and LSP support for code. RAD Studio’s C++ Builder version comes with the award-winning VCL framework for high-performance native Windows apps and the powerful FireMonkey (FMX) framework for cross-platform UIs.
There is a free C++ Builder Community Edition for students, beginners, and startups; it can be downloaded from here. For professional developers, there are Professional, Architect, or Enterprise versions of C++ Builder and there is a trial version you can download from here.