Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run a C program in Visual Studio Code?

I used to use Replit for my IDE, but I want to try Visual Studio Code (VSC) because my teacher said VSC was a great IDE to use. So I took a program I wrote a while back and put it in, but when I try to run the program, it just keeps telling me that I need to install an extension environment for C, because VSC doesn't come with one naturally. I already downloaded the C/C++ extension advised by Microsoft but it still isn't working. Any ideas as to what I'm doing wrong?

Also, here is the extension id: ms-vscode.cpptools

like image 305
CamdenJ Avatar asked Dec 06 '25 13:12

CamdenJ


2 Answers

The guide for using C++ with Visual Studio Code is located here:

  • C/C++ for Visual Studio Code

If you are using the windows operating system, you can install the Microsoft Visual C++ (MSVC) compiler toolset as described here:

  • Configure VS Code for Microsoft C++

Otherwise you should read the tutorials for the compiler you want to use:

  • Tutorials for other compilers

The reason I refer to links, instead of explaining the details here, is because the answer might become outdated/obsolete. Sometimes links are better than explanations.

like image 161
GoWiser Avatar answered Dec 08 '25 05:12

GoWiser


Step 1. Download the MinGW - Minimalist GNU for Windows at SourceForge, link here.

When you download Minimalist GNU for Windows (MinGW), you can choose which packages to install. You should select the following packages:

  • mingw-developer-toolkit
  • mingw32-base
  • mingw32-gcc-g++
  • msys-base

Then click on the Installation tab on the top left and click on Apply Changes.

After installation, go to your C Drive where the MinGW is installed, and enter the folders MinGW > bin. Copy the path C:\MinGW\bin

Now search for environment, and enter edit environment variables for your account. screenshot

Next, double-click on Path, click on New, paste the path C:\MinGW\bin, press enter, and click OK.

Verify that it has been installed correctly by opening up Command Prompt and typing in gcc --version. It should give you the current version number.

Step 2. In Visual Studio Code, click on the Extensions tab, search and install Code Runner by Jun Han

Step 3. In the C/C++ Configurations. Make sure the Compiler Path has c:/MinGW/bin/gcc.exe selected. screenshot 2

You can get to it by opening Command Pallet (ctrl+shift+p) typing in C/++: Select a Configuration.. then select Edit Configurations (UI)

like image 20
Tony Ruiz Avatar answered Dec 08 '25 06:12

Tony Ruiz



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!