C 编程环境搭建 Window 篇

前言 - 简介git

  咱们在写代码的过程当中, 不可避免的重度依赖所处的开发环境. 本文重点带你们在 Window 搭建 Cshell

简单控制台项目. 看成存档, 用于记录项目搭建各类重复操做.  在详细过程以前, 咱们约定下基础环境数据库

  Best new version Windowapi

  Best new version Visual Studio多线程

例如笔者当前是 Windows 10 + Visual Studio 2019, 其中 Windows 推荐开启 UTF-8 支持. spa

那此间, 骚年去唤醒本身的道 ~ 命令行

 

正文 - 过程线程

  正文分三个过程. 其一是 Visual Studio C Consule 经常使用设置. 其二是导出模板, 来解放生产力. 其三演示使用.调试

Visual Studio C Consule 经常使用设置rest

1. 建立 c_template 项目

  

 

2. 只保留 x64 环境

人的精气有限, 作钉子更省力.

3. 添加基础 main.c

4. Visual Studio 项目详细配置

a). 区域环境配置

项目右击 -> [配置属性] -> [高级] -> [字符集] -> [未设置]

b). 添加包含库
项目右击 -> [配置属性] -> [连接器] -> [输入]

psapi.lib
user32.lib
shell32.lib
ws2_32.lib
userenv.lib
iphlpapi.lib
advapi32.lib

c). 添加预编译处理器
项目右击 -> [配置属性] -> [C/C++]-> [预处理器] -> [预处理器定义]

[Debug]
_DEBUG

[Release]
NDEBUG
 
_LARGEFILE_SOURCE
_FILE_OFFSET_BITS=64
WIN32_LEAN_AND_MEAN
_CRT_SECURE_NO_WARNINGS
_CRT_NONSTDC_NO_DEPRECATE
_WINSOCK_DEPRECATED_NO_WARNINGS

d). 设置编译额外选项
项目右击 -> [配置属性] -> [C/C++] -> [常规] -> [调试信息格式] -> [程序数据库 (/Zi)]
项目右击 -> [配置属性] -> [C/C++] -> [代码生成] -> [运行库] -> [多线程/MT]
项目右击 -> [配置属性] -> [C/C++] -> [高级] -> [编译为] -> [编译为C代码/TC]
项目右击 -> [配置属性] -> [C/C++] -> [高级] -> [禁用特定警告] -> [4098]
项目右击 -> [配置属性] -> [C/C++] -> [命令行] -> [/D "restrict=__restrict"]
项目右击 -> [配置属性] -> [连接器] -> [常规] -> [启用增量连接] -> [否 (/INCREMENTAL:NO)]
项目右击 -> [配置属性] -> [连接器] -> [系统] -> [子系统] -> [控制台]
项目右击 -> [配置属性] -> [连接器] -> [命令行] -> /IGNORE:4099
 
详细配置遇到不明白能够自行搜索, 能够图了解, 也能够 求精深

 

导出模板

  上面这些每次操做都添加, 很恶心. 咱们能够经过 [项目] -> [导出模板] 一劳永逸. ~

1. 前戏

  找到 c_template.vcxproj 项目文件, 经过你的慧眼, 将其中全部关于 Win32 相关的 xml 配置删除.

 

2. 导出模板

[项目] -> [导出模板]

添加额外补充

(图片什么的能够因本身喜爱本身整)

 

演示使用

最终生成以下模板内容

不妨既兴经过这个模板演示一段代码 

#include <stdio.h> #include <float.h> #include <errno.h> #include <assert.h> #include <limits.h> #include <stdlib.h> #include <string.h> #include <stddef.h> #include <stdint.h> #include <stdbool.h>

/* 题目: 地上右一个 m 行 n 列的方格. 一个机器人从坐标(0, 0) 的格子开始移动, 它每次能够向左, 右, 上, 下移动一格, 但不能进入行坐标和列坐标的数位之和大于 k 的格子. 例如, 当 k 为 18 的时候, 机器人可以进入方格 (35, 37), 由于 3 + 5 + 3 + 7 = 18. 但它不能进入方格 (35, 38), 由于 3 + 5 + 3 + 9 = 19. 请问该机器人可以到达多少个格子? */

extern int moving_count(int m, int n, int threshold); int main(int argc, char * argv[]) { int m = 20, n = 20, threshold = 10; int count = moving_count(m, n, threshold); printf("<m = %d, n = %d, threshold = %d> -> %d\n", m, n, threshold, count); return 0; } struct visite { int rows; int cols; int threshold; bool visited[]; }; inline struct visite * visite_create(int rows, int cols, int threshold) { struct visite * v = malloc(sizeof(struct visite) + (rows * cols) * sizeof (int)); assert(v && rows > 0 && cols > 0 && threshold > 0); v->rows = rows; v->cols = cols; v->threshold = threshold; memset(v->visited, 0, (rows * cols) * sizeof (int)); return v; } inline void visite_delete(struct visite * v) { if (v) free(v); } static inline int get_digit_sum(int num) { int sum = 0; while (num > 0) { sum = num % 10; num /= 10; } return sum; } inline bool visite_check(struct visite * v, int row, int col) { if (row >= 0 && row < v->rows && col >= 0 && col < v->cols && !v->visited[row * v->cols + col]) { return get_digit_sum(row) + get_digit_sum(col) <= v->threshold; } return false; } int visite_moving(struct visite * v, int row, int col) { if (!visite_check(v, row, col)) return 0; v->visited[row * v->cols + col] = true; return 1 + visite_moving(v, row, col - 1) + visite_moving(v, row, col + 1) + visite_moving(v, row - 1, col) + visite_moving(v, row + 1, col); } int moving_count(int m, int n, int threshold) { if (m < 0 || n < 0 || threshold < 0) return 0; if (threshold == 0) return 1; struct visite * v = visite_create(m, n, threshold); int count = visite_moving(v, 0, 0); visite_delete(v); return count; }

(有心的道友, 也能够转成栈回溯. )

 

后记 - 展望

错误是不免的, 欢迎朋友指正互相印证苦中做乐.

明月照小楼

 立秋 - 刘翰 - 南宋 乳鸦啼散玉屏空,一枕新凉一扇风。 睡起秋声无觅处,满阶梧桐月明中。
相关文章
相关标签/搜索