Developing C Language Applications Using VSCode

After setting up the C language development environment, the next step is to create a project for development.

For convenience, it is generally recommended to use an IDE (Integrated Development Environment) for development.

There are many development tools for C language, with the mainstream ones being Clion, Visual Studio, and VSCode.

This article will demonstrate using VSCode.

Creating a Project

  1. Install VSCode.

    It is recommended to install it directly from the Microsoft application store:

    Developing C Language Applications Using VSCode
  2. Install extensions.

    After installing VSCode, go to its extension marketplace to install the C/C++ Extension Pack and Code Runner:

    Developing C Language Applications Using VSCode
  3. Check these three options in the settings.

    Developing C Language Applications Using VSCode
  4. Create a project.

    Create a folder (it is recommended to use a name with pure English characters), such as learn; then open VSCode, and under File, select **Open Folder…**, choose the created folder and open it:

    Developing C Language Applications Using VSCode

Writing Code

  1. Hovering over the opened folder will reveal 4 shortcut buttons; clicking the first one on the left allows you to create a new file in the folder, name it hello.c:

    Developing C Language Applications Using VSCode
  2. Enter simple code in hello.c.

    #include<stdio.h>
    
    int main()
    {
        printf("Hello World\n");
        return 0; 
    }

Running Code

  1. In the Terminal, click **Configure Tasks…**:

    Developing C Language Applications Using VSCode

    Then, a subfolder named .vscode will be automatically created in the folder, and a file named tasks.json will be automatically created in this subfolder, which does not require any modifications.

  2. Finally, return to the hello.c file, right-click and select Run Code to run the code.

    Developing C Language Applications Using VSCode

    The output will be displayed in the Terminal below:

    Developing C Language Applications Using VSCode

Debugging Code

  1. Set a breakpoint in the code line:

    Developing C Language Applications Using VSCode
  2. Click Run and then Start Debugging:

    In the subsequent pop-up window, select **C++(GDB/LLDB)**:

    Developing C Language Applications Using VSCode

    Then select gcc.exe:

    Developing C Language Applications Using VSCode
  3. The code will run to the breakpoint, and debugging can begin.

    Developing C Language Applications Using VSCode
  4. After the first configuration, you can also click the Debug button in the upper right corner for debugging:

    Developing C Language Applications Using VSCode

Thus, you can use VSCode for C language development.

Leave a Comment