How to run a c program in terminal in windows ?
To install MinGW in Windows, you can follow these steps:
- Download the MinGW installer from the official website (https://osdn.net/projects/mingw/downloads/68260/mingw-get-setup.exe/).
- Run the downloaded installer file.
- Select “Download latest repository catalogs” and click “Next”.
- Choose the installation directory where you want MinGW to be installed. The default directory is C:\MinGW. Click “Next” to continue.
- Choose the components you want to install. At minimum, you should select “mingw32-base” and “mingw32-gcc-g++”. You can also select additional components if needed. Click “Next” to continue.
- Choose the installation type. “Installation” is the recommended option. Click “Next” to continue.
- Click “Install” to begin the installation process.
- Once the installation is complete, add the MinGW bin directory to your system’s PATH environment variable. To do this, right-click on “My Computer” or “This PC”, select “Properties”, click “Advanced system settings”, click “Environment Variables”, scroll down to “System Variables”, select “Path”, click “Edit”, and add the path to the MinGW bin directory (e.g. C:\MinGW\bin) to the list of paths.
- Verify that MinGW is installed correctly by opening a command prompt and running the command
gcc --version
. This should display the version number of the installed GCC compiler.
That’s it! MinGW is now installed on your Windows system and ready to use. You can use it to compile and run C and C++ programs on your computer.
To run a C program in the terminal on Windows, you can follow these steps:
- Open the Command Prompt by pressing the “Windows key + R” to open the Run dialog, then type “cmd” and press Enter.
- Navigate to the directory where your C program is stored using the
cd
command. For example, if your program is stored in a folder called “my_programs” on your desktop, you would enter the following command:
cd C:\Users\YourUserName\Desktop\my_programs
Replace “YourUserName” with your Windows username.
- Compile your C program using the
gcc
command followed by the name of your C file. For example, if your C file is called “hello.c”, you would enter the following command:
gcc hello.c
This will create an executable file called “a.exe” in the same directory as your C file.
- Run your C program using the
./
command followed by the name of your executable file. For example, if your executable file is called “a.exe”, you would enter the following command:
./a.exe
This will execute your C program in the terminal, and any output from your program will be displayed on the screen.
Note: If your C program has any external dependencies or requires additional libraries, you may need to specify these when compiling your program using the -l
or -I
flags with the gcc
command. Check the documentation for your specific libraries or dependencies for more information on how to include them in your compilation process.
Leave a Comment