From ec6b7900295acb775b6a7e2d2e6f7a6d0cfc7399 Mon Sep 17 00:00:00 2001 From: woodrabbit Date: Sat, 22 Jul 2023 15:35:28 +0800 Subject: [PATCH 1/3] Redesign the source file and directory structure 1. Redesign the source file main.c 2. The source files are placed in the src directory, and the documentation is placed in the docs directory. Files with the file name set to Gitee ID will be placed in the directory above src. Signed-off-by: woodrabbit --- PR/2023/src/main.c | 31 +++++++++++++++++++++++++++++++ PR/2023/woodrabbit/main.c | 10 ---------- 2 files changed, 31 insertions(+), 10 deletions(-) create mode 100644 PR/2023/src/main.c delete mode 100644 PR/2023/woodrabbit/main.c diff --git a/PR/2023/src/main.c b/PR/2023/src/main.c new file mode 100644 index 0000000..739854a --- /dev/null +++ b/PR/2023/src/main.c @@ -0,0 +1,31 @@ +#include +#include +#include +#include + +int main() { + DIR *dir = opendir(".."); + if (dir == NULL) { + perror("Unable to open parent directory"); + return 1; + } + + struct dirent *entry; + + while ((entry = readdir(dir)) != NULL) { + // 只处理常规文件(排除目录、软链接等)。 + // 另外,排除“.”和“..”目录项。并且排除 + // 带有扩展名的文件(其中包含“.”),因为 + // 该程序要求将文件名设置成Gitee ID,因此 + // 其中不可能包含“.”。 + if (entry->d_type == DT_REG && + strchr(entry->d_name, '.') == NULL) { + printf("Greetings from %s\n", entry->d_name); + } + } + + closedir(dir); + + printf(":)\n"); + return 0; +} diff --git a/PR/2023/woodrabbit/main.c b/PR/2023/woodrabbit/main.c deleted file mode 100644 index 643a530..0000000 --- a/PR/2023/woodrabbit/main.c +++ /dev/null @@ -1,10 +0,0 @@ -#include - -/* Please fill in your own Gitee ID here. */ -char *pMyGiteeId = "woodrabbit"; - -int main(void) { - printf("Greetings from %s!\n", pMyGiteeId); - return 0; -} - -- Gitee From 695deffd57ad3ae2c6cd8c8e104fc0cce88e2b30 Mon Sep 17 00:00:00 2001 From: woodrabbit Date: Sat, 22 Jul 2023 15:47:22 +0800 Subject: [PATCH 2/3] Add a comment Signed-off-by: woodrabbit --- PR/2023/src/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/PR/2023/src/main.c b/PR/2023/src/main.c index 739854a..50f3c2a 100644 --- a/PR/2023/src/main.c +++ b/PR/2023/src/main.c @@ -4,6 +4,8 @@ #include int main() { + // 将文件名设置成Gitee ID的文件将置于该源代码文件 + // 所生成可执行文件的上级目录。 DIR *dir = opendir(".."); if (dir == NULL) { perror("Unable to open parent directory"); -- Gitee From 5ed2f33b284258617d7b4d0a89883e65defb6ffb Mon Sep 17 00:00:00 2001 From: woodrabbit Date: Sat, 22 Jul 2023 16:52:39 +0800 Subject: [PATCH 3/3] Add comments and updated the printing information for the program Signed-off-by: woodrabbit --- PR/2023/src/main.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/PR/2023/src/main.c b/PR/2023/src/main.c index 50f3c2a..2c93e13 100644 --- a/PR/2023/src/main.c +++ b/PR/2023/src/main.c @@ -15,14 +15,16 @@ int main() { struct dirent *entry; while ((entry = readdir(dir)) != NULL) { - // 只处理常规文件(排除目录、软链接等)。 - // 另外,排除“.”和“..”目录项。并且排除 - // 带有扩展名的文件(其中包含“.”),因为 - // 该程序要求将文件名设置成Gitee ID,因此 - // 其中不可能包含“.”。 + // 1. 只处理常规文件(排除目录、软链接等)。 + // 2. 排除“.”和“..”目录项,并排除带有扩展名的文件 + // (其中包含“.”)。根据Gitee ID命名规则,其中 + // 不可能包含“.”。 + // 3. Gitee ID命名规则:只允许字母、数字或者下划线 + // (_)、中划线(-),至少 2 个字符,必须 + // 以字母开头,不能以特殊字符结尾。 if (entry->d_type == DT_REG && strchr(entry->d_name, '.') == NULL) { - printf("Greetings from %s\n", entry->d_name); + printf("Greetings from %s!\n", entry->d_name); } } -- Gitee