Get the App
SLTechnology News&Howtos  ›  Internet Technology  › 

An example of writing a c program by vscode

Shulou Source: shulou.com Published: 2022-06-02 18:18:27 10月30日 Update

Editor to share with you an example of vscode writing c program, I believe that most people do not know much about it, so share this article for your reference, I hope you can learn a lot after reading this article, let's go to know it!

How does vscode write c programs?

Get the CAccord Category + extension

Open vscode

Ctrl+shift+x, open the store.

Search for CAccord Category +

Install and restart vscode

Recommended for related tutorials: vscode tutorial

Install GCC

Download MinGW

Open the installer, install to disk D (need to create a MinGW folder), and generate the MinGW installation manager after the installation is complete.

Manager automatically opens (if not manually), click All Packages, select gcc.bin,g++.bin,gdb.bin, click Installation, select Apply Changes, click Apply submit to install

Win+R, enter control to enter the control panel, click system and install-> system-> Advanced system Settings-> Environment variables, find Path- > Edit-> New, and paste the bin folder path of the installed MinGW.

Configure Smart Tip

Write a test file demo.c, click the "prompt light" under the introduced standard library, and generate the c_cpp_properties.json file.

Edit c_cpp_properties.json

C_cpp_properties.json modifies as follows: {"configurations": [{"name": "Win32", "includePath": ["${workspaceFolder} / * *"], "defines": ["_ DEBUG", "UNICODE" "_ UNICODE"], "windowsSdkVersion": "8.1", "compilerPath": "D:\\ MinGW\\ bin\\ gcc.exe", / / the gcc path on your computer "cStandard": "c11", "cppStandard": "clock17", "intelliSenseMode": "msvc-x64"}] "version": 4}

Turn on debugging function

F5 or Ctrl+F5 enable debugging, select C++ (GDB/LLDB) to generate launch.json file, and modify as follows:

{/ / use IntelliSense to learn about the relevant properties. / / hover to see a description of an existing property. / / for more information Please visit https://go.microsoft.com/fwlink/?linkid=830387 "version": "0.2.0", "configurations": [{"name": "(gdb) Launch", "type": "cppdbg", "request": "launch", "program": "${workspaceFolder} / ${fileBasenameNoExtension} .exe" / / debugged program "args": [], "stopAtEntry": false, "cwd": "${workspaceFolder}", "environment": [], "externalConsole": true, "MIMode": "gdb", "miDebuggerPath": "D:\\ MinGW\\ bin\\ gdb.exe" / / gdb "preLaunchTask" of your computer: "echo", / / the name of the task to be executed before debugging: "setupCommands": [{"description": "Enable pretty-printing for gdb", "text": "- enable-pretty-printing" "ignoreFailures": true}]}]}

Ctrl+Shift+P, enter the Tasks:Configure Task configuration task, select the module to create the task.json file, select the Others template, and generate the task.json file. Modify as follows:

{/ / See https://go.microsoft.com/fwlink/?LinkId=733558 / / for the documentation about the tasks.json format "version": "2.0.0", "tasks": [{"label": "echo", / / Task name "type": "shell", "command": "gcc" "args": ["- g", "${file}", "- o", "${fileBasenameNoExtension} .exe" / / generate a debuggable execution file]}]}

If there is an error: process termination, exit code: 1, it may be that gcc has not been loaded by the editor (test method: open the console, enter gcc, see the prompt), restart the editor.

These are all the contents of this article entitled "examples of writing c programs in vscode". Thank you for reading! I believe we all have a certain understanding, hope to share the content to help you, if you want to learn more knowledge, welcome to follow the industry information channel!

Tags: Files programs generation selection tasks content articles systems prompts input examples information names properties tutorials folders more computers editors paths Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno MariaDB Linux Shulou Technology macOS Shulou Information