我的第一个C语言程序
准备工作
-
一本自学教材,比如“老掉牙的谭浩强”
image.png
-- 就是它👆
- 环境
- 安装C语言运行环境 mingw64 自行百度
-
配置VScode运行环境,要增加两个关键的配置文件
image.png
launch.json👇
{
// 使用 IntelliSense 了解相关属性。
// 悬停以查看现有属性的描述。
// 欲了解更多信息,请访问: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "g++.exe - 生成和调试活动文件",
"type": "cppdbg",
"request": "launch",
"program": "${fileDirname}\\${fileBasenameNoExtension}.exe",
"args": [],
"stopAtEntry": false,
"cwd": "${workspaceFolder}",
"environment": [],
"externalConsole": false,
"MIMode": "gdb",
"miDebuggerPath": "D:\\Program Files\\mingw64\\bin\\gdb.exe",
"setupCommands": [
{
"description": "为 gdb 启用整齐打印",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
],
"preLaunchTask": "C/C++: g++.exe build active file"
}
]
}
tasks.json👇
{
"tasks": [
{
"type": "shell",
"label": "C/C++: g++.exe build active file",
"command": "D:\\Program Files\\mingw64\\bin\\g++.exe",
"args": [
"-g",
"${file}",
"-o",
"${fileDirname}\\${fileBasenameNoExtension}.exe"
],
"options": {
"cwd": "${workspaceFolder}"
},
"problemMatcher": [
"$gcc"
],
"group": {
"kind": "build",
"isDefault": true
}
}
],
"version": "2.0.0"
}
---- miDebuggerPath 路径就是安装 mingw64 的路径!
---- preLaunchTask内容要与label一致!
开整!
先写一个简单的
#include <stdio.h>
int main()
{
printf("This is my first C program! \n");
return 0;
}
调试一下
image.png
完美,收工!!!