Site icon Learn C++

How To Run A C Program in Command Prompt

How To Run A C Program in Command Prompt

C is one of the most powerful programming languages and it can be run by the C++ IDE and compilers. Using a fast and reliable C or C++ compiler for Windows is very important for beginners and professionals since it helps C/C++ developers in remembering which language features exist, how to use them, and even detect errors when we get them wrong. The C language still extremely popular among developers. Today, we explain how to run a simple C program in the command prompt, power shell or in DOS terminal, or how you can use a C++ IDE and Command Prompt ?

How to develop and run a C program in command prompt with C++ Builder?

Because of their shared ancestry, you can run C code using C++ compilers and build tools like C++ Builder. C++ Builder has free C++ Builder Community Edition and C++ Builder Professional / Architect / Enterprise versions.

1. Start by downloading and installing a copy of C++ Builder if you haven’t done that yet.
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 essentially made from text files, which means you can use any editor to edit these kind of programs. Notepad, Notepad++ and the excellent UltraEdit. But C++ IDE’s have many more specialized features to edit, debug, test, and run a C program. Then run your IDE and start a new project. Now you can write your C code.

When you start coding, first of all, you should include libraries that you use. Generally for beginners stdio.h library is enough to do simple beginner apps. We can include this library as below,

[crayon-6741d0db22aea407629190/]

Second, you should add the main procedure (the main program, the main function) as below,

[crayon-6741d0db22af3763853027/]

After that you should write your programming code lines into this procedure, between { and } brackets. If you are a beginner “Hello World” examples are good to understand feature of that programming language. It is good to understand how to edit text, how to write in its format, how to compile and link, how to debug and execute, how to deploy or release. This full example below is a “Hello World” C example that can be run with C++ Builder.

[crayon-6741d0db22af4693805822/]

In C++, after every command you use you should put ; to the end of your commands. 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 successfully run and exit.

In this example above we define main() function as a 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 run and exit.

3. You can simply press Run Button or F9 key to compile and run, or you can use Menu to compile and Run too.

4. If you want to run this program in Console then execute RAD Studio Command Prompt from the Windows menu in Windows. This will open 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,

[crayon-6741d0db22af5730006866/]

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,

[crayon-6741d0db22af8702170109/]

How to run a C program in command prompt with a free C++ compiler?

There are different Embarcadero C++ Compilers for different purposes or device targets. These are bcc, bcc32c, bcc32x, bccaarm, bcc64 executable compilers. developed 2012-2022 Embarcadero Technologies, Inc. There is a free Win32 compiler. Note that a C++ compiler is not a full IDE like RAD Studio but simply reads the C program code and turns it into a program.

This free download of the C++ Compiler includes C11 language support, the Dinkumware STL (Standard Template Library) framework, and the complete Embarcadero C/C++ Runtime Library (RTL). In this free version, you’ll also find a number of C/C++ command line tools—such as the high-performance linker and resource compiler.

The Free C++ Compiler download includes:

C++Builder includes compilers for Win32, Win64 and iOS. And, C++Builder also features a modern, high-productivity RAD Studio IDE, debugger tools, and enterprise connectivity for to accelerate cross-platform UI development. Learn more about RAD Studio on its product page.

To execute a C program in terminal,

You can simply use the C++ compiler to compile C programs in terminal. For example, if your C program file is called myproject.c you can compile this with optimization level 2 (-o2) as below,

[crayon-6741d0db22af9112536090/]

How to run a C program in command prompt with the GNU C/C++ compiler?

GNU GCC is another powerful C/C++ compiler originally written as the compiler for the Unix, Linux and GNU operating system. The GNU system was developed to be 100% free software, and it is efficient with both 32-bit and 64-bit operations. This compiler can be used on Windows using MinGW or CygWin Linux Simulators. Compiled executable files need a small dll to run independently on Windows. It is mostly compatible with CLANG standards.

The GCC Compiler can be used by Visual Studio Code, Dev C++, Code Blocks, and can be directly used with Command Prompt or PowerShell. It is available on the official product page https://gcc.gnu.org/.

GNU C/C++ compilers can be directly used in Linux or it can be used with MinGW Linux Simulation (with GNU C/C++ Compiler) to develop C++ applications running on the command console. It is the most well-known compiler in Linux.

How to compile and run a C program in Linux terminal?

In Linux, GNU C/C++ comes as default language installed. Generally gcc compiler is used as a C compiler and g++ compiler is used as C++ compiler. If your c program file is myapp.c you can compile this with gcc command as below,

[crayon-6741d0db22afa057808478/]

Be sure that you have permission to write to folder there. Now you can easily run your myapp.out as given below,

[crayon-6741d0db22afc945954549/]

Here is the full input and output process in Linux terminal

[crayon-6741d0db22afd582487838/]

How to run a C program in command prompt with a professional C++ compiler?

In general, you can run c programs with the latest C++ Compilers and Editors today. C++ Builder Professional, Enterprise and Architect Editions are able to run C programs. There is a free C++ Builder Community Edition for students, beginners, and startups too. Simply you can download, install and run your C programs in console applications. Moreover you can enhance your C programs with C++ features and modern GUIs, which means you can mix and use C and C++ together. For the best modern app, later if you wish, you can update your C program to a C++ program.

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. C++ Builder comes with Rapid Application Development Studio, also known as RAD Studio, and C++ Builder is one of the most professional IDE’s that work under RAD Studio. It is the evolution of one of the very first IDE systems (it began as Borland TurboC in 1990 and was later renamed Borland C++ Builder). Under the Embarcadero brand it continues to thrive with regular new releases and updates. 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.

The Latest RAD Studio C++ Builder Welcome Screen

You can simply use RAD Studio Command Prompt to compile and execute C programs in terminal. For example, if your c program file is myproject.c you can compile this with optimization level 2 (-o2) as below,

[crayon-6741d0db22afe430887750/]

Professional developers can use the Professional, Architect or Enterprise versions of C++ Builder. Please visit https://www.embarcadero.com/products/cbuilder.

Download RAD Studio 11 Now

See What’s New in RAD Studio 11

Exit mobile version