Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Visual Studio Code task to compile and run C programs

Introduction

The below code is the configuration for the Microsoft Visual Code tasks which will enable you to compile and run C program

Steps

  1. Press Cmd + Shift + P
  2. Type Configure task ( A task.json file will be created for that project )
  3. Copy below configuration code and save it.

Usage

Simple press Cmd + Shift + B to compile and run.

Note: Make sure you select the tab having C program as below tasks run on active tab in VS Code.

Task Config

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "compile and run C",
            "type": "shell",
            "command": "gcc ${file} -o ${fileBasenameNoExtension}  && ./${fileBasenameNoExtension} ",
            "presentation": {
                "reveal": "always",
                "panel": "shared"
            },
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ]
}
@Agarwal-Nikhil

This comment has been minimized.

Copy link

commented May 10, 2018

Thanks, it works!

@ukulsh

This comment has been minimized.

Copy link

commented Jun 26, 2018

its giving an error && in not a valid statement separator in this verson

@lanzorg

This comment has been minimized.

Copy link

commented Aug 23, 2018

@ukulsh
You have to use ; instead of && on Windows.

@deekshithanand

This comment has been minimized.

Copy link

commented Oct 20, 2018

Isn't it possible to have 2 different task files so that you can have 2 different keybindings assigned to
them and run build task and run task separately?

@aman-shaw

This comment has been minimized.

Copy link

commented Feb 1, 2019

thank you

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.