How to Run C Program in Command Prompt
How to Run C Program in Command Prompt
If you've written or downloaded some C code on your Windows PC, you'll need to compile the code to turn it into an program you can run. This simple wikiHow tutorial will walk you through compiling and running a C program from the Windows command prompt using MinGW, an easy-to-install version of the GCC compiler.
Steps

Install MinGW, a simple C compiler. If you haven't already done so, you'll need to install a C compiler on your PC to compile the C program. Compiling the C code will turn the 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 the installation. When you get to the MinGW Installation Manager window, you'll see several packages in the upper-right panel. Check the boxes next to "mingw32-base" and "mingw-gcc-g++." Click the Installation menu and select Apply Changes. Click Apply.

Add the compiler's path to your system environment variables. This step makes it easier to run the compiler from the command prompt, as you won't have to enter the full path to 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:\MinGW\bin and click OK. Click OK and OK again.

Open a Command Prompt window as an administrator. To do this, press the Windows key, type cmd, right-click Command Prompt, and then select Run as Administrator. Once the prompt window is open, double-check that the compiler installed properly (and that the environment variables are set) by running the command gcc -- version at the prompt. If you already had a command prompt window open, close it and open another so the path you added

Use the cd command to go to the directory where your C program is saved. For example, if the program you want to compile is in C:\MyPrograms, type cd C:\MyPrograms and press Enter.

Run the gcc command to compile your C program. The syntax you'll use is gcc filename.c -o filename.exe. This compiles the program and makes it executable. Replace filename.c with the name of the file containing your C code, and filename.exe with the name you want to give the compiled program. Make sure you give the compiled program a name that ends with .exe. The -o flag specifies the output file.

Type the name of your new program and press ↵ Enter. For example, if you created a program called hello.exe, you can type hello or hello.exe. This runs your C program from the command prompt.

What's your reaction?

Comments

https://sharpss.com/assets/images/user-avatar-s.jpg

0 comment

Write the first comment for this!