diff --git a/Labs/Solutions/Lab2-Sol.tar.gz b/Labs/Solutions/Lab2-Sol.tar.gz new file mode 100644 index 0000000..c68aa70 Binary files /dev/null and b/Labs/Solutions/Lab2-Sol.tar.gz differ diff --git a/Labs/lab2/Lab2.tar.gz b/Labs/lab2/Lab2.tar.gz new file mode 100644 index 0000000..868b4c3 Binary files /dev/null and b/Labs/lab2/Lab2.tar.gz differ diff --git a/Labs/lab2/lab2.md b/Labs/lab2/lab2.md new file mode 100644 index 0000000..c482fc4 --- /dev/null +++ b/Labs/lab2/lab2.md @@ -0,0 +1,111 @@ +# Lab2 C 语言基本语法 +## Lab2_1 C 语言基本语法 +- 完成lab2_1中的四个.c文件 + - 请根据每个ex_中的TODO完成内容。 + - 你可以使用 make 自动编译可执行文件 + ```bash + make # 编译所有可执行文件 + make ex1_ptr # 仅编译 ex1_ptr.c + ./ex1_ptr # 运行 ex1_ptr + make clean # 删除可执行文件 + ``` + +## Lab2_2 字符串和循环 +- 本实验使用了参数char *argv[],请在编译后尝试向程序输入命令行参数,如: + ```bash + make + ./str_and_cyc California Oregon Washington Texas + ``` + 输出内容,如下所示: + ```bash + for: + arg 1: California + arg 2: Oregon + arg 3: Washington + arg 4: Texas + + state 0: California + state 1: Oregon + state 2: Washington + state 3: Texas + + while: + arg 0: ./str_and_cyc + arg 1: California + arg 2: Oregon + arg 3: Washington + arg 4: Texas + + state 0: California + state 1: Oregon + state 2: Washington + state 3: Texas + ``` +- 请对srt_and_cyc.c文件中的for和while循环尝试以下操作并查看结果。 +- for循环 + - 将i初始化为0看看会发生什么。是否也需要改动argc,不改动的话它能正常工作吗?为什么下标从0开始可以正常工作? + - 将num_states改为错误的值(使它变大),来看看会发生什么。 + - RTFM: NULL是什么东西,尝试将它用做states的一个元素,看看它会打印出什么。 + - 看看你是否能在打印之前将states的一个元素赋值给argv中的元素,再试试相反的操作。 +- while循环 + - 使用while循环将argv中的值复制到states。 + - 让这个复制循环不会执行失败,即使argv之中有很多元素也不会全部放进states。 + - 研究你是否真正复制了这些字符串。答案可能会让你感到意外和困惑。 + + +## 递归(可选,难度较大) + +- 经典递归例子 + + ```C + #include + int fibonacci(int n) { + if (n < 1) { + return -1; + } + if (n == 1 || n == 2) { + return 1; + } + else { + return fibonacci(n - 1) + fibonacci(n - 2); + } + } + + int main(void) + { + int a; + while (scanf("%d", &a) != EOF) { + printf("Fibonacci数列第%d项为:%d\n", a, fibonacci(a)); + } + return 0; + } + ``` + +- 理解递归的重要方式 + - Base Case:递归主体以一个基本情况开始,通常它是这个条件语句,定义了函数对最简单的输入的行为,并通常被用作递归结束的出口。 + - Recursive Calls:在Base Case之后,是一个或多个递归调用。递归调用总是有一个特点:它们简化了原来的问题。 + - 数学归纳法理解: + 1. 验证递归函数`F(X)`取Base Case时成立. + 2. 假设X = n时成立,那么可以推导出在X = n+1时递归函数`F(X)`做出正确的行为。 + 3. 最后一步总结表述。 + +- 数独 + + - 数独(Sudoku)是一种经典的逻辑数字游戏,通常由一个9x9的网格组成,这个网格被进一步划分为9个3x3的小方块。游戏的目标是通过填充数字1到9,使得每一行、每一列和每一个3x3的小方块都包含数字1到9,且数字不能重复。 + + - 实现一个递归函数`bool solveSudoku(int board[N][N], int row, int col)`判断数独是否可解,有解则填充正确答案。 + + - 题中数独采用二维数组,需解答填充的数字用0代替如: + + 0 6 0 0 0 0 0 7 1 + 7 0 5 4 0 3 0 0 0 + 0 0 0 6 7 0 3 0 0 + 0 3 7 2 4 1 8 6 0 + 0 0 0 0 0 5 1 9 0 + 1 5 8 7 9 0 2 3 0 + 6 0 1 0 2 0 0 0 3 + 0 7 9 0 0 0 5 0 2 + 0 0 0 0 0 4 7 0 0 + 提供了`printBoard(int board[N][N])`函数打印数独和`isSafe(int board[N][N], int row, int col, int num)`函数检查数字是否可以放在board[row][col]位置。 + - 运行judge.sh检测程序正确性。 +- 完成文件`sudoku.c`中的`solveSudoku`函数编写。 diff --git a/Others/Codes/Lecture1/README.md b/Lectures/Lecture1/Codes/README.md similarity index 100% rename from Others/Codes/Lecture1/README.md rename to Lectures/Lecture1/Codes/README.md diff --git a/Others/Codes/Lecture1/float.c b/Lectures/Lecture1/Codes/float.c similarity index 100% rename from Others/Codes/Lecture1/float.c rename to Lectures/Lecture1/Codes/float.c diff --git a/Others/Codes/Lecture1/hello-world.c b/Lectures/Lecture1/Codes/hello-world.c similarity index 100% rename from Others/Codes/Lecture1/hello-world.c rename to Lectures/Lecture1/Codes/hello-world.c diff --git a/Others/Codes/Lecture1/makefile b/Lectures/Lecture1/Codes/makefile similarity index 75% rename from Others/Codes/Lecture1/makefile rename to Lectures/Lecture1/Codes/makefile index 50caf2e..c6b051f 100644 --- a/Others/Codes/Lecture1/makefile +++ b/Lectures/Lecture1/Codes/makefile @@ -1,5 +1,5 @@ CC := gcc -CFLAGS := -Wall -Werror -Wpedantic -g -std=c11 +CFLAGS := -Wall -Wextra -Werror -g -std=c11 TARGET := float hello-world all: $(TARGET) diff --git a/Lectures/Lecture2/Codes/1-control-flow.c b/Lectures/Lecture2/Codes/1-control-flow.c new file mode 100644 index 0000000..52d6bd9 --- /dev/null +++ b/Lectures/Lecture2/Codes/1-control-flow.c @@ -0,0 +1,70 @@ +/* C 语言中的控制流 */ +#include +#include + +int main(int argc, char *argv[]) { + // 条件分支 + // if else + if (argc == 1) { + printf("args = NULL\n"); + } else if (argc == 2) { + printf("args = %d\n", argc - 1); + printf("argv:%s\n", argv[1]); + } else { + printf("args = %d\n", argc - 1); + } + + printf("\n"); + + // switch + switch (argc) { + case 1: + printf("args = NULL\n"); + break; + case 2: + printf("args = %d\n", argc - 1); + printf("argv:%s\n", argv[1]); + break; + default: + printf("args = %d\n", argc - 1); + break; + } + + // 三元表达式 + argc == 2 ? printf("yes\n\n") : printf("no\n\n"); + + // 循环结构 + int i = 10; + while (i != 0) { + printf("%d ", i); + i--; + } + printf("\n"); + + do { + printf("%d ", i); + i++; + } while (i < 10); + printf("\n"); + + for (i = 0; i < 10; i++) { + printf("%d ", i); + } + printf("\n\n"); + + // 跳转控制语句 + /** + * @statement break; 跳出循环或者是跳出switch语句 + * @statement continue; 跳过下面的步骤重新开始下一次循环 + */ + printf("goto语句示范:\n"); + int go = 0; +lable: + printf("%d ", go); + if (go < 3) { + go++; + goto lable; + } + printf("\n"); + return EXIT_SUCCESS; +} diff --git a/Lectures/Lecture2/Codes/2-function.c b/Lectures/Lecture2/Codes/2-function.c new file mode 100644 index 0000000..6cf1431 --- /dev/null +++ b/Lectures/Lecture2/Codes/2-function.c @@ -0,0 +1,22 @@ +#include +#include + +// 函数声明 +int fact(int); + +int main(void) { + printf("%d", fact(5)); + return EXIT_SUCCESS; +} + +// 函数定义 +int fact(int n) { + if (n <= 1) { + return 1; + } + int sum = 1, i; + for (i = 1; i <= n; i++) { + sum *= i; + } + return sum; +} diff --git a/Lectures/Lecture2/Codes/3-array.c b/Lectures/Lecture2/Codes/3-array.c new file mode 100644 index 0000000..9ffe555 --- /dev/null +++ b/Lectures/Lecture2/Codes/3-array.c @@ -0,0 +1,20 @@ +#include +#include + +int main(void) { + // 定义 + unsigned char temp[10] = {0x11, 0x15, 0x22}; + + // 数组的地址 + printf("temp address: %p\n", temp); + + // 更改 + temp[3] = 0xa8; + + // 使用 + for (size_t i = 0; i < 10; i++) { + printf("%02x ", temp[i]); + } + printf("\n"); + return EXIT_SUCCESS; +} diff --git a/Lectures/Lecture2/Codes/4-string.c b/Lectures/Lecture2/Codes/4-string.c new file mode 100644 index 0000000..e5593ca --- /dev/null +++ b/Lectures/Lecture2/Codes/4-string.c @@ -0,0 +1,14 @@ +#include +#include +#include + +/* 字符串以'\0'结尾 */ + +int main(void) { + char str1[] = "I Can Eat Glass"; + char str2[20] = "I Can Eat Glass"; + + printf("str1:%s\nsize:%lu\nstr2:%s\nsize:%lu\n", str1, strlen(str1), str2, + strlen(str2)); + return EXIT_SUCCESS; +} diff --git a/Lectures/Lecture2/Codes/5-string-advance.c b/Lectures/Lecture2/Codes/5-string-advance.c new file mode 100644 index 0000000..ac00572 --- /dev/null +++ b/Lectures/Lecture2/Codes/5-string-advance.c @@ -0,0 +1,31 @@ +#include +#include +#include + +/* string.h标准库的几个常用函数 */ + +int main(void) { + char str1[] = "I Can Eat Glass"; + char str2[] = "Neko Bytes"; + + printf("str1:%s\nsize:%lu\nstr2:%s\nsize:%lu\n", str1, strlen(str1), str2, + strlen(str2)); + + // 字符串比较 + int h = strcmp(str1, str2); + if (h != 0) { + if (h > 0) { + printf("str1更大\n"); + } else { + printf("str2更大\n"); + } + } else { + printf("str1和str2一样大\n"); + } + + // 字符串赋值 + strcpy(str1, "I love windows\n"); + printf("str1:%s", str1); + + return EXIT_SUCCESS; +} diff --git a/Lectures/Lecture2/Codes/6-macro.c b/Lectures/Lecture2/Codes/6-macro.c new file mode 100644 index 0000000..c0d8145 --- /dev/null +++ b/Lectures/Lecture2/Codes/6-macro.c @@ -0,0 +1,9 @@ +#include + +#define MAX 1000 + +int main(void) { + printf("MAX: %d", MAX); + + return 0; +} diff --git a/Lectures/Lecture2/Codes/7-variable.c b/Lectures/Lecture2/Codes/7-variable.c new file mode 100644 index 0000000..9529139 --- /dev/null +++ b/Lectures/Lecture2/Codes/7-variable.c @@ -0,0 +1,13 @@ +#include + +int main(void) { + unsigned int a; + int b; + float c; + printf("a,b,c各元素的值\n"); + printf("%u %d %f\n", a, b, c); + printf("a,b,c各元素的地址\n"); + printf("%p %p %p\n", &a, &b, &c); + + return 0; +} diff --git a/Lectures/Lecture2/Codes/8-nested-array.c b/Lectures/Lecture2/Codes/8-nested-array.c new file mode 100644 index 0000000..f0ade09 --- /dev/null +++ b/Lectures/Lecture2/Codes/8-nested-array.c @@ -0,0 +1,11 @@ +#include + +int main(void) { + int matrix[2][2] = {{1, 2}, {3, 4}}; + printf("%p %p %p %p\n", &matrix[0][0], &matrix[0][1], &matrix[1][0], + &matrix[1][1]); + printf("sizeof matrix: %zu\n", sizeof matrix); + printf("sizeof matrix[0]: %zu\n", sizeof matrix[0]); + printf("sizeof matrix[1]: %zu\n", sizeof matrix[1]); + return 0; +} diff --git a/Lectures/Lecture2/Codes/9-pointer.c b/Lectures/Lecture2/Codes/9-pointer.c new file mode 100644 index 0000000..908809a --- /dev/null +++ b/Lectures/Lecture2/Codes/9-pointer.c @@ -0,0 +1,23 @@ +#include + +void swap1(int x, int y) { + int t = x; + x = y; + y = t; +} + +void swap2(int *x, int *y) { + int t = *x; + *x = *y; + *y = t; +} + +int main(void) { + int a = 1, b = 2; + printf("a = %d, b = %d\n", a, b); + swap1(a, b); + printf("a = %d, b = %d after swap1\n", a, b); + swap2(&a, &b); + printf("a = %d, b = %d after swap2\n", a, b); + return 0; +} diff --git a/Lectures/Lecture2/Codes/B-pointer-clac.c b/Lectures/Lecture2/Codes/B-pointer-clac.c new file mode 100644 index 0000000..25de566 --- /dev/null +++ b/Lectures/Lecture2/Codes/B-pointer-clac.c @@ -0,0 +1,14 @@ +#include + +int main(void) { + int array[10] = {0}; + printf("array = %p\n", array); + int *p1 = array, *p2 = array; + printf("p1 = %p, p2 = %p\n", p1, p2); + p1 = p1 + 1; + printf("p1 = %p, p2 = %p\n", p1, p2); + p2 = p2 + 9; + printf("p1 = %p, p2 = %p\n", p1, p2); + printf("p2 - p1 = %u\n", (unsigned int)(p2 - p1)); + return 0; +} diff --git a/Lectures/Lecture2/Codes/README.md b/Lectures/Lecture2/Codes/README.md new file mode 100644 index 0000000..19ea348 --- /dev/null +++ b/Lectures/Lecture2/Codes/README.md @@ -0,0 +1,7 @@ +在本目录下打开终端,输入: + +```bash +make +``` + +在`./build`目录下生成对应的可执行文件 diff --git a/Lectures/Lecture2/Codes/makefile b/Lectures/Lecture2/Codes/makefile new file mode 100644 index 0000000..a4be07c --- /dev/null +++ b/Lectures/Lecture2/Codes/makefile @@ -0,0 +1,17 @@ +BUILD_DIR = ./build +CC := gcc +CFLAGS := -Wall -Wextra -g -std=c11 +SRCS := $(wildcard *.c) +TARGETS := $(SRCS:%.c=$(BUILD_DIR)/%) + +all: $(TARGETS) + +$(BUILD_DIR)/%: %.c + @mkdir -p $(dir $@) + $(CC) $(CFLAGS) -o $@ $< + +clean: + -rm -rf $(BUILD_DIR) + +.PHONY: clean all + diff --git a/Lectures/Lecture2/Lecture2/index.html b/Lectures/Lecture2/Lecture2/index.html index 31bf89c..0b76f53 100644 --- a/Lectures/Lecture2/Lecture2/index.html +++ b/Lectures/Lecture2/Lecture2/index.html @@ -12,7 +12,7 @@ type="text/css"> Lecture3 - + + + + - \ No newline at end of file + diff --git a/Lectures/Lecture2/Lecture2/static/img/04c55e39a9fa4c7aa2edca121fb4bc52.png b/Lectures/Lecture2/Lecture2/static/img/04c55e39a9fa4c7aa2edca121fb4bc52.png new file mode 100644 index 0000000..fcefbf9 Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/04c55e39a9fa4c7aa2edca121fb4bc52.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/12462e9d74c8489bb110338d748228c6.png b/Lectures/Lecture2/Lecture2/static/img/12462e9d74c8489bb110338d748228c6.png new file mode 100644 index 0000000..8fec29e Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/12462e9d74c8489bb110338d748228c6.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/16a82e9965414299a076175865f6bea8.png b/Lectures/Lecture2/Lecture2/static/img/16a82e9965414299a076175865f6bea8.png new file mode 100644 index 0000000..e6e7385 Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/16a82e9965414299a076175865f6bea8.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/2325487fe87c4df293bbfbe7986d8fe9.png b/Lectures/Lecture2/Lecture2/static/img/2325487fe87c4df293bbfbe7986d8fe9.png new file mode 100644 index 0000000..4da99cd Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/2325487fe87c4df293bbfbe7986d8fe9.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/276ea65bb0824b8ab636b2eaea91d478.png b/Lectures/Lecture2/Lecture2/static/img/276ea65bb0824b8ab636b2eaea91d478.png new file mode 100644 index 0000000..76d41f1 Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/276ea65bb0824b8ab636b2eaea91d478.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/3e722aa87b43462fa5629d7d5b542743.png b/Lectures/Lecture2/Lecture2/static/img/3e722aa87b43462fa5629d7d5b542743.png new file mode 100644 index 0000000..48cbd69 Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/3e722aa87b43462fa5629d7d5b542743.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/505d39ab3d4a4f969b90552a6c5477cc.svg b/Lectures/Lecture2/Lecture2/static/img/505d39ab3d4a4f969b90552a6c5477cc.svg new file mode 100644 index 0000000..c92fe15 --- /dev/null +++ b/Lectures/Lecture2/Lecture2/static/img/505d39ab3d4a4f969b90552a6c5477cc.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Lectures/Lecture2/Lecture2/static/img/9697bafbcaf14e97872e3fe646a5af93.png b/Lectures/Lecture2/Lecture2/static/img/9697bafbcaf14e97872e3fe646a5af93.png new file mode 100644 index 0000000..7b316de Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/9697bafbcaf14e97872e3fe646a5af93.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/aa1e8bce43c640a3bb4c63867e2f68a0.png b/Lectures/Lecture2/Lecture2/static/img/aa1e8bce43c640a3bb4c63867e2f68a0.png new file mode 100644 index 0000000..7f345fa Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/aa1e8bce43c640a3bb4c63867e2f68a0.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/baf1ff76a5814d75bf99e5b2725d95e3.png b/Lectures/Lecture2/Lecture2/static/img/baf1ff76a5814d75bf99e5b2725d95e3.png new file mode 100644 index 0000000..7af4219 Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/baf1ff76a5814d75bf99e5b2725d95e3.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/d2218f607d3a4237973e1fbd7506fb67.png b/Lectures/Lecture2/Lecture2/static/img/d2218f607d3a4237973e1fbd7506fb67.png new file mode 100644 index 0000000..4bb479d Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/d2218f607d3a4237973e1fbd7506fb67.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/d48aeab415ac4fdea9b473afe3e429b7.png b/Lectures/Lecture2/Lecture2/static/img/d48aeab415ac4fdea9b473afe3e429b7.png new file mode 100644 index 0000000..1f08847 Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/d48aeab415ac4fdea9b473afe3e429b7.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/d77fc3c248284ce88073e56b5498914f.png b/Lectures/Lecture2/Lecture2/static/img/d77fc3c248284ce88073e56b5498914f.png new file mode 100644 index 0000000..934a4f5 Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/d77fc3c248284ce88073e56b5498914f.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/eb0c14e67ede4c6982f672d1f23f8347.png b/Lectures/Lecture2/Lecture2/static/img/eb0c14e67ede4c6982f672d1f23f8347.png new file mode 100644 index 0000000..1f08847 Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/eb0c14e67ede4c6982f672d1f23f8347.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/f7640ea9a80d4963bfe259c5f15245f6.png b/Lectures/Lecture2/Lecture2/static/img/f7640ea9a80d4963bfe259c5f15245f6.png new file mode 100644 index 0000000..4bb479d Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/f7640ea9a80d4963bfe259c5f15245f6.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/f9b5785898c74ccb93861c27c0dd6460.png b/Lectures/Lecture2/Lecture2/static/img/f9b5785898c74ccb93861c27c0dd6460.png new file mode 100644 index 0000000..51d2759 Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/f9b5785898c74ccb93861c27c0dd6460.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/favicon.png b/Lectures/Lecture2/Lecture2/static/img/favicon.png new file mode 100644 index 0000000..c9f0e1a Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/favicon.png differ diff --git a/Lectures/Lecture2/Lecture2/static/img/ff8bee4432db4457af8cb7accf38a3c8.png b/Lectures/Lecture2/Lecture2/static/img/ff8bee4432db4457af8cb7accf38a3c8.png new file mode 100644 index 0000000..ce4e9fa Binary files /dev/null and b/Lectures/Lecture2/Lecture2/static/img/ff8bee4432db4457af8cb7accf38a3c8.png differ diff --git a/Notes/week0.pdf b/Notes/week0.pdf index d423639..cbdb8fd 100644 Binary files a/Notes/week0.pdf and b/Notes/week0.pdf differ diff --git a/Notes/week1.pdf b/Notes/week1.pdf index 6da403b..5bfd4c7 100644 Binary files a/Notes/week1.pdf and b/Notes/week1.pdf differ diff --git a/Notes/week2.pdf b/Notes/week2.pdf index 7930199..bccb883 100644 Binary files a/Notes/week2.pdf and b/Notes/week2.pdf differ diff --git a/Others/Codes/Lecture2/1-control-flow.c b/Others/Codes/Lecture2/1-control-flow.c deleted file mode 100644 index c8135ef..0000000 --- a/Others/Codes/Lecture2/1-control-flow.c +++ /dev/null @@ -1,69 +0,0 @@ -#include - -// C中的控制流 - -int main(int argc,char* argv[]){ - // 条件分支 - // if else - if(argc == 1){ - printf("args = NULL\n"); - }else if(argc == 2){ - printf("args = %d\n",argc-1); - printf("argv:%s\n",argv[1]); - }else{ - printf("args = %d\n",argc-1); - } - - printf("\n"); - - //switch - switch (argc) - { - case 1: - printf("args = NULL\n"); - break; - case 2: - printf("args = %d\n",argc-1); - printf("argv:%s\n",argv[1]); - break; - default: - printf("args = %d\n",argc-1); - break; - } - - // 三元表达式 - argc == 2? printf("yes\n\n") : printf("no\n\n"); - - // 循环结构 - int i=10; - while(i!=0){ - printf("%d ",i); - i--; - }printf("\n"); - - do{ - printf("%d ",i); - i++; - }while(i<10); - printf("\n"); - - for(i=0;i<10;i++){ - printf("%d ",i); - }printf("\n\n"); - - // 跳转控制语句 - /** - * @param break 跳出循环或者是跳出switch语句 - * @param continue 跳过下面的步骤重新开始下一次循环 - */ - printf("goto语句示范:\n"); - int go = 0; - lable: - printf("%d ",go); - if(go < 3){ - go++; - goto lable; - } - printf("\n"); -} - diff --git a/Others/Codes/Lecture2/2-function.c b/Others/Codes/Lecture2/2-function.c deleted file mode 100644 index 9887b86..0000000 --- a/Others/Codes/Lecture2/2-function.c +++ /dev/null @@ -1,20 +0,0 @@ -#include - -// 函数声明 -int fact(int); - -int main(){ - printf("%d",fact(5)); -} - -// 函数定义 -int fact(int n){ - if (n<=1){ - return 1; - } - int sum=1,i; - for(i=1;i<=n;i++){ - sum*=i; - } - return sum; -} diff --git a/Others/Codes/Lecture2/3-array.c b/Others/Codes/Lecture2/3-array.c deleted file mode 100644 index b2575c8..0000000 --- a/Others/Codes/Lecture2/3-array.c +++ /dev/null @@ -1,19 +0,0 @@ -#include - -int main(){ - // 定义 - unsigned char temp[10] = {0x11,0x15,0x22}; - - // 数组的地址 - printf("temp address: %p\n",temp); - - // 更改 - temp[3] = 0xa8; - - // 使用 - for (size_t i=0;i<10;i++){ - printf("%02x ",temp[i]); - } - printf("\n"); - return 0; -} diff --git a/Others/Codes/Lecture2/4-string.c b/Others/Codes/Lecture2/4-string.c deleted file mode 100644 index 5a742fe..0000000 --- a/Others/Codes/Lecture2/4-string.c +++ /dev/null @@ -1,12 +0,0 @@ -#include -#include - -// 字符串以\0结尾 - -int main(){ - char str1[] = "I Can Eat Glass"; - char str2[20] = "I Can Eat Glass"; - - printf("str1:%s\nsize:%lu\nstr2:%s\nsize:%lu\n",\ - str1,strlen(str1),str2,strlen(str2)); -} diff --git a/Others/Codes/Lecture2/5-string-advance.c b/Others/Codes/Lecture2/5-string-advance.c deleted file mode 100644 index c2ec05e..0000000 --- a/Others/Codes/Lecture2/5-string-advance.c +++ /dev/null @@ -1,32 +0,0 @@ -#include -#include - -// string.h标准库的几个常用函数 - -int main(){ - char str1[] = "I Can Eat Glass"; - char str2[] = "我能吞下玻璃而不伤身体"; - - printf("str1:%s\nsize:%lu\nstr2:%s\nsize:%lu\n",\ - str1,strlen(str1),str2,strlen(str2)); - - // 字符串比较 - int h = strcmp(str1,str2); - if(h!=0){ - if(h>0){ - printf("str1更大\n"); - } - else{ - printf("str2更大\n"); - } - } - else{ - printf("str1和str2一样大\n"); - } - - // 字符串赋值 - strcpy(str1,"I love windows\n"); - printf("str1:%s",str1); - - return 0; -} diff --git a/Others/Codes/Lecture2/6-macro.c b/Others/Codes/Lecture2/6-macro.c deleted file mode 100644 index be52743..0000000 --- a/Others/Codes/Lecture2/6-macro.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -#define MAX 1000 - -int main(int argc,char* argv[]) -{ - printf("MAX: %d",MAX); - - return 0; -} diff --git a/Others/Codes/Lecture2/7-variable.c b/Others/Codes/Lecture2/7-variable.c deleted file mode 100644 index cdfa014..0000000 --- a/Others/Codes/Lecture2/7-variable.c +++ /dev/null @@ -1,13 +0,0 @@ -#include - -int main(){ - unsigned int a; - int b; - float c; - printf("a,b,c各元素的值\n"); - printf("%u %d %f\n",a,b,c); - printf("a,b,c各元素的地址\n"); - printf("%p %p %p\n",&a,&b,&c); - - return 0; -} diff --git a/Others/Codes/Lecture2/8-nested-array b/Others/Codes/Lecture2/8-nested-array deleted file mode 100644 index c1cd558..0000000 --- a/Others/Codes/Lecture2/8-nested-array +++ /dev/null @@ -1,10 +0,0 @@ -#include - -int main(void) { - int matrix[2][2] = { {1, 2}, {3, 4} }; - printf("%p %p %p %p\n", &matrix[0][0], &matrix[0][1], &matrix[1][0], &matrix[1][1]); - printf("sizeof matrix: %d\n", sizeof matrix); - printf("sizeof matrix[0]: %d\n", sizeof matrix[0]); - printf("sizeof matrix[1]: %d\n", sizeof matrix[1]); - return 0; -} diff --git a/Others/Codes/Lecture2/9-pointer.c b/Others/Codes/Lecture2/9-pointer.c deleted file mode 100644 index e0ebafd..0000000 --- a/Others/Codes/Lecture2/9-pointer.c +++ /dev/null @@ -1,23 +0,0 @@ -#include - -void swap1(int x, int y) { - int t = x; - x = y; - y = t; -} - -void swap2(int *x, int *y) { - int t = *x; - *x = *y; - *y = t; -} - -int main(void) { - int a = 1, b = 2; - printf("a = %d, b = %d\n", a, b); - swap1(a, b); - printf("a = %d, b = %d after swap1\n", a, b); - swap2(&a, &b); - printf("a = %d, b = %d after swap2\n", a, b); - return 0; -} diff --git a/Others/Codes/Lecture2/A-pointer-puzzle.c b/Others/Codes/Lecture2/A-pointer-puzzle.c deleted file mode 100644 index 8ea50dc..0000000 --- a/Others/Codes/Lecture2/A-pointer-puzzle.c +++ /dev/null @@ -1,7 +0,0 @@ -#include - -int main(void) { - // int* (*p)[20][10]; - // p是一个指向 存放int*类型的二维数组 的指针 - -} diff --git a/Others/Codes/Lecture2/B-pointer-clac.c b/Others/Codes/Lecture2/B-pointer-clac.c deleted file mode 100644 index 879cb93..0000000 --- a/Others/Codes/Lecture2/B-pointer-clac.c +++ /dev/null @@ -1,14 +0,0 @@ -#include - -int main(void) { - int array[10] = {0}; - printf("array = %p\n", array); - int *p1 = array, *p2 = array; - printf("p1 = %p, p2 = %p\n", p1, p2); - p1 = p1 + 1; - printf("p1 = %p, p2 = %p\n", p1, p2); - p2 = p2 + 9; - printf("p1 = %p, p2 = %p\n", p1, p2); - printf("p2 - p1 = %u\n", (unsigned int)(p2-p1)); - return 0; -} diff --git a/Others/Codes/Lecture2/README.md b/Others/Codes/Lecture2/README.md deleted file mode 100644 index 4bc0702..0000000 --- a/Others/Codes/Lecture2/README.md +++ /dev/null @@ -1,5 +0,0 @@ -> 在本目录下打开终端,输入 -```bash -make -``` -> 在`./build`目录下生成对应的可执行文件 diff --git a/Others/Codes/Lecture2/makefile b/Others/Codes/Lecture2/makefile deleted file mode 100644 index 08406d1..0000000 --- a/Others/Codes/Lecture2/makefile +++ /dev/null @@ -1,21 +0,0 @@ -CC = gcc - -CFLAGS = -Wall -g - -SRC = $(wildcard *.c) - -EXE = $(patsubst %.c, ./build/%, $(SRC)) - -.PHONY: all -all: build_dir $(EXE) - -./build/%: %.c - $(CC) $(CFLAGS) -o $@ $< - -build_dir: - mkdir -p build - -.PHONY: clean -clean: - rm -rf ./build - diff --git a/site.sh b/site.sh index 1443a94..76884b6 100755 --- a/site.sh +++ b/site.sh @@ -5,9 +5,10 @@ SOURCE=("$WORK_DIR/index.html" "$WORK_DIR/Lectures") mkdir -p "$SITE_DIR" cp -r "${SOURCE[@]}" "$SITE_DIR" -CODE_DIR="$WORK_DIR/Others/Codes" JEKLLY_TOOL_DIR="$WORK_DIR/Tools/ghpages-mini-fileserver" -cp -r "$CODE_DIR" "$JEKLLY_TOOL_DIR/resources" +RESOURCE="$JEKLLY_TOOL_DIR/resources" +mkdir -p "$RESOURCE" +find "$WORK_DIR/Lectures" -type d -name "Codes" -exec cp -r "{}" "$RESOURCE" \; bash "$JEKLLY_TOOL_DIR/prenodes.sh" cd "$JEKLLY_TOOL_DIR" && bundle exec jekyll build --baseurl "$1" cp -r "$JEKLLY_TOOL_DIR/_site" "$SITE_DIR"