• About
  • Contact
  • Cookie
  • Disclaimer
  • Privacy Policy
  • Change the purpose of use

Tnhelearning.edu.vn - Various useful general information portal

  • Photo
  • Bio
  • How To
  • Tech

How to Run C Programs in Command Prompt

November 7, 2023 by admin Category: How To

You are viewing the article How to Run C Programs in Command Prompt  at Tnhelearning.edu.vn you can quickly access the necessary information in the table of contents of the article below.

X

This article is co-authored by a team of editors and trained researchers who confirm the accuracy and completeness of the article.

The wikiHow Content Management team carefully monitors the work of editors to ensure that every article is up to a high standard of quality.

This article has been viewed 3,047 times.

If you’ve written or downloaded some C programming language code on your Windows PC, you’ll need to compile it to turn the code into a program you can run. This simple wikiHow will walk you through the steps of compiling and running a C program from the Windows command prompt using MinGW, an easy-to-install version of the GCC compiler.

Steps

Image titled Run C Program in Command Prompt Step 1

Image titled Run C Program in Command Prompt Step 1

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/2/2f/Run-C-Program-in-Command-Prompt-Step-1.jpg/v4-728px-Run-C- Program-in-Command-Prompt-Step-1.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/2/2f/Run-C-Program-in-Command-Prompt- Step-1.jpg/v4-728px-Run-C-Program-in-Command-Prompt-Step-1.jpg”,”smallWidth”:460,”smallHeight”:348,”bigWidth”:728,”bigHeight” :550,”licensing”:”<div class=”mw-parser-output”></div>”}
Install MinGW – simple C compiler. If you haven’t already, you need to install a C compiler on your PC to compile the C program. This process will turn the C code into an executable C program. MinGW is one of the easiest options to install for Windows:

  • Download MinGW from https://sourceforge.net/projects/mingw.
  • Double-click the downloaded file and follow the on-screen instructions to prepare for the installation.
  • When you reach the MinGW Installation Manager window, you will see many installation packages in the upper right pane.
  • Check the boxes next to “mingw32-base” and “mingw-gcc-g++.”
  • Click the Installation menu and select Apply Changes .
  • Click Apply .
Image titled Run C Program in Command Prompt Step 2

Image titled Run C Program in Command Prompt Step 2

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/3/37/Run-C-Program-in-Command-Prompt-Step-2.jpg/v4-728px-Run-C- Program-in-Command-Prompt-Step-2.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/3/37/Run-C-Program-in-Command-Prompt- Step-2.jpg/v4-728px-Run-C-Program-in-Command-Prompt-Step-2.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
Add the compiler path to the system environment variable. This step will make it easy for the compiler to run from the command prompt, just as you won’t need to enter the full path into the GCC program.

  • Press the Windows key and type environment . Click Edit the system environment variables in the search results.
  • Click the Environment Variables… button.
  • Select the “Path” option under “System variables” and click Edit…
  • Click New .
  • Type C:MinGWbin and click OK .
  • Click OK and OK again.
READ More:   How to do self piercing at home
Image titled Run C Program in Command Prompt Step 3

Image titled Run C Program in Command Prompt Step 3

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/4/4e/Run-C-Program-in-Command-Prompt-Step-3.jpg/v4-728px-Run-C- Program-in-Command-Prompt-Step-3.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/4/4e/Run-C-Program-in-Command-Prompt- Step-3.jpg/v4-728px-Run-C-Program-in-Command-Prompt-Step-3.jpg”,”smallWidth”:460,”smallHeight”:348,”bigWidth”:728,”bigHeight” :550,”licensing”:”<div class=”mw-parser-output”></div>”}
Open a Command Prompt window as administrator. To proceed, press the Windows key, type cmd , right-click Command Prompt and select Run as Administrator .

  • After the command prompt window opens, double check that the compiler is properly installed (and that the environment variables are set) by executing the gcc -- version command.
  • If a command prompt window is open, close and reopen a new window to display the path you added earlier.
Image titled Run C Program in Command Prompt Step 4

Image titled Run C Program in Command Prompt Step 4

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/7/72/Run-C-Program-in-Command-Prompt-Step-4.jpg/v4-728px-Run-C- Program-in-Command-Prompt-Step-4.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/7/72/Run-C-Program-in-Command-Prompt- Step-4.jpg/v4-728px-Run-C-Program-in-Command-Prompt-Step-4.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
Use the cd command to go to the directory where the C program is saved. For example, if the program you want to compile is in C:MyPrograms, type cd C:MyPrograms and press Enter .
Image titled Run C Program in Command Prompt Step 5

Image titled Run C Program in Command Prompt Step 5

{“smallUrl”:”https://www.wikihow.com/images_en/thumb/5/5e/Run-C-Program-in-Command-Prompt-Step-5.jpg/v4-728px-Run-C- Program-in-Command-Prompt-Step-5.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/5/5e/Run-C-Program-in-Command-Prompt- Step-5.jpg/v4-728px-Run-C-Program-in-Command-Prompt-Step-5.jpg”,”smallWidth”:460,”smallHeight”:345,”bigWidth”:728,”bigHeight” :546,”licensing”:”<div class=”mw-parser-output”></div>”}
Execute the gcc command to compile the C program. The syntax you will use will be gcc filename.c -o filename.exe . The program will be compiled and become executable.

  • Replace filename.c with the file name containing the C code, and filename.exe with the name you want to give the program after compiling.
  • Check to make sure that the program name you set has the extension .exe .
  • The -o flag specifies the output file.
  • Image titled Run C Program in Command Prompt Step 6

    Image titled Run C Program in Command Prompt Step 6

    {“smallUrl”:”https://www.wikihow.com/images_en/thumb/4/47/Run-C-Program-in-Command-Prompt-Step-6.jpg/v4-728px-Run-C- Program-in-Command-Prompt-Step-6.jpg”,”bigUrl”:”https://www.wikihow.com/images/thumb/4/47/Run-C-Program-in-Command-Prompt- Step-6.jpg/v4-728px-Run-C-Program-in-Command-Prompt-Step-6.jpg”,”smallWidth”:460,”smallHeight”:346,”bigWidth”:728,”bigHeight” :547,”licensing”:”<div class=”mw-parser-output”></div>”}
    Type the new program name and press ↵ Enter . For example, if you create a program named hello.exe , you can type hello or hello.exe . The C program will be run from the command prompt.
  • X

    This article is co-authored by a team of editors and trained researchers who confirm the accuracy and completeness of the article.

    The wikiHow Content Management team carefully monitors the work of editors to ensure that every article is up to a high standard of quality.

    READ More:   How to cut the hair on the back of the head yourself

    This article has been viewed 3,047 times.

    If you’ve written or downloaded some C programming language code on your Windows PC, you’ll need to compile it to turn the code into a program you can run. This simple wikiHow will walk you through the steps of compiling and running a C program from the Windows command prompt using MinGW, an easy-to-install version of the GCC compiler.

    Thank you for reading this post How to Run C Programs in Command Prompt at Tnhelearning.edu.vn You can comment, see more related articles below and hope to help you with interesting information.

    Related Search:

    Related Posts

    How to Create Curved Text in Photoshop
    How to fall asleep faster
    How to Install FBReader to Read eBooks

    Category: How To

    Previous Post: « Top 999+ beautiful god images – Amazing Collection beautiful god images Full 4K
    Next Post: Top 999+ Water Dragon Wallpaper Full HD, 4K✅Free to Use »

    Copyright © 2025 · Tnhelearning.edu.vn - Useful Knowledge