From 472c1acb8903e2e8a46ec4d08699d24e4dc66df3 Mon Sep 17 00:00:00 2001 From: feilong Date: Fri, 22 Oct 2021 19:09:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0include=E6=8C=87=E4=BB=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../calc.h" | 23 +++++++++++++++++++ .../calc.json" | 18 +++++++++++++++ .../calc_test.c" | 10 ++++++++ .../calc_test.json" | 16 +++++++++++++ .../config.json" | 5 +++- 5 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 "data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc.h" create mode 100644 "data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc.json" create mode 100644 "data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc_test.c" create mode 100644 "data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc_test.json" diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc.h" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc.h" new file mode 100644 index 0000000..ad31e15 --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc.h" @@ -0,0 +1,23 @@ +// 标题: 定义一个 C语言的头文件 +// 描述: 头文件可以被其他文件代码通过 #include "xxx.h" +// 导入,下面哪个选项的头文件的实现正确。 + +#ifndef CALC_H +#define CALC_H + +int calc(char op, int x, int y) { + switch (op) { + case '+': + return x + y; + case '-': + return x - y; + case '*': + return x * y; + case '/': + return x / y; + default: + return 0; + } +} + +#endif \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc.json" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc.json" new file mode 100644 index 0000000..f258bec --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc.json" @@ -0,0 +1,18 @@ +{ + "type": "code_options", + "author": "幻灰龙", + "source": "calc.h", + "multiline":[ + { + "#ifndef CALC_H": "", + "#define CALC_H": "", + "#endif": "" + }, + { + "#define CALC_H": "" + }, + { + "#ifndef CALC_H": "" + } + ] +} \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc_test.c" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc_test.c" new file mode 100644 index 0000000..cdc3d49 --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc_test.c" @@ -0,0 +1,10 @@ +// 标题: 简易四则运算 +// 描述: 假设"calc.h"和本文件在同一个目录下,计算 (1+2)*(2-1)/2 + +#include "calc.h" +#include + +int main(int argc, char **args) { + printf("%d", calc('/', calc('*', calc('+', 1, 2), calc('-', 2, 1)), 2)); + return 0; +} \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc_test.json" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc_test.json" new file mode 100644 index 0000000..0aa413c --- /dev/null +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/calc_test.json" @@ -0,0 +1,16 @@ +{ + "type": "code_options", + "author": "幻灰龙", + "source": "calc_test.c", + "multiline":[ + { + "#include \"calc.h\"":"#include " + }, + { + "#include \"calc.h\"":"using \"calc.h\"" + }, + { + "#include \"calc.h\"":"#include(\"calc.h\")" + } + ] +} \ No newline at end of file diff --git "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/config.json" "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/config.json" index 1def284..d26f4d1 100644 --- "a/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/config.json" +++ "b/data/3.C\350\257\255\350\250\200\351\253\230\351\230\266/4.\351\242\204\345\244\204\347\220\206\345\231\250/2.#include\346\214\207\344\273\244/config.json" @@ -6,5 +6,8 @@ "C语言" ], "children": [], - "export": [] + "export": [ + "calc.json", + "calc_test.json" + ] } \ No newline at end of file -- GitLab