From 8b915eadbb0caa0a4df13561da10bf55efd1e462 Mon Sep 17 00:00:00 2001 From: "hengxin(Hengfeng Wei)" Date: Thu, 19 Sep 2024 12:13:03 +0800 Subject: [PATCH] +hello.c, +guess.c --- .gitignore | 91 +++++++++++++++++++++++++++++++++++++ .idea/.gitignore | 10 ++++ .idea/2024-cpl-coding.iml | 2 + .idea/codestream.xml | 6 +++ .idea/git_toolbox_blame.xml | 6 +++ .idea/misc.xml | 7 +++ .idea/modules.xml | 8 ++++ .idea/vcs.xml | 6 +++ CMakeLists.txt | 7 +++ guess.c | 60 ++++++++++++++++++++++++ hello.c | 32 +++++++++++++ 11 files changed, 235 insertions(+) create mode 100644 .idea/.gitignore create mode 100644 .idea/2024-cpl-coding.iml create mode 100644 .idea/codestream.xml create mode 100644 .idea/git_toolbox_blame.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 .idea/vcs.xml create mode 100644 CMakeLists.txt create mode 100644 guess.c create mode 100644 hello.c diff --git a/.gitignore b/.gitignore index c6127b3..3897fc1 100644 --- a/.gitignore +++ b/.gitignore @@ -50,3 +50,94 @@ modules.order Module.symvers Mkfile.old dkms.conf + +CMakeLists.txt.user +CMakeCache.txt +CMakeFiles +CMakeScripts +Testing +Makefile +cmake_install.cmake +install_manifest.txt +compile_commands.json +CTestTestfile.cmake +_deps +CMakeUserPresets.json + +# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider +# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839 + +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# Gradle and Maven with auto-import +# When using Gradle or Maven with auto-import, you should exclude module files, +# since they will be recreated, and may cause churn. Uncomment if using +# auto-import. +# .idea/artifacts +# .idea/compiler.xml +# .idea/jarRepositories.xml +# .idea/modules.xml +# .idea/*.iml +# .idea/modules +# *.iml +# *.ipr + +# CMake +cmake-build-*/ + +# Mongo Explorer plugin +.idea/**/mongoSettings.xml + +# File-based project format +*.iws + +# IntelliJ +out/ + +# mpeltonen/sbt-idea plugin +.idea_modules/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Cursive Clojure plugin +.idea/replstate.xml + +# SonarLint plugin +.idea/sonarlint/ + +# Crashlytics plugin (for Android Studio and IntelliJ) +com_crashlytics_export_strings.xml +crashlytics.properties +crashlytics-build.properties +fabric.properties + +# Editor-based Rest Client +.idea/httpRequests + +# Android studio 3.1+ serialized cache file +.idea/caches/build_file_checksums.ser \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..a70f8da --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,10 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml +# CodeStream ignored files +/../../2024-cpl-coding\.idea/codestream.xml diff --git a/.idea/2024-cpl-coding.iml b/.idea/2024-cpl-coding.iml new file mode 100644 index 0000000..f08604b --- /dev/null +++ b/.idea/2024-cpl-coding.iml @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/.idea/codestream.xml b/.idea/codestream.xml new file mode 100644 index 0000000..d294c70 --- /dev/null +++ b/.idea/codestream.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/git_toolbox_blame.xml b/.idea/git_toolbox_blame.xml new file mode 100644 index 0000000..7dc1249 --- /dev/null +++ b/.idea/git_toolbox_blame.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..0b76fe5 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,7 @@ + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..dbced12 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..987df67 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 3.25) +project(2024-cpl-coding C) + +set(CMAKE_C_STANDARD 17) + +add_executable(hello hello.c) +add_executable(guess guess.c) \ No newline at end of file diff --git a/guess.c b/guess.c new file mode 100644 index 0000000..a96676d --- /dev/null +++ b/guess.c @@ -0,0 +1,60 @@ +// +// Created by hfwei on 2024/9/19. +// + +#include +#include +#include + +int main(void) { + int high = 100; + int chance = 7; + + /* + * print the rule of the game + */ + printf("The computer will generate a random number between 1 and %d\n" + "You have %d chances.\n", + high, chance); + /* + * generate a random number + */ + srand(time(NULL)); // use current time as seed for random generator + // 0 .. RAND_MAX + // 1 .. high + int secret = rand() % high + 1; + printf("secret = %d\n", secret); + + while (chance > 0) { + + /* + * let the player enter his/her guess number + */ + printf("Enter your guess.\n"); + + /* + * store the guess number, + * compare it with the secret, + * and inform the player of the result + */ + int guess; + scanf("%d", &guess); + + if (guess == secret) { + printf("You Win!\n"); + break; + } else if (guess > secret) { + printf("guess > secret\n"); + } else { + printf("guess < secret\n"); + } + + /* + * loop: repeat until the player wins or loses + */ + chance--; + // chance = chance - 1; + } + + return 0; +} \ No newline at end of file diff --git a/hello.c b/hello.c new file mode 100644 index 0000000..629da8a --- /dev/null +++ b/hello.c @@ -0,0 +1,32 @@ +// +// Created by hfwei on 2024/9/19. +// + +// single-line comment +// Created by hfwei on 2023/9/15. +// + +/* + * this is a multi-line comment + * this is a multi-line comment + */ + +// directive +// .h: header file +// stdio: standard input/output +#include + +/* + * main function + * y <- f(x) + * int: integer (return) + */ +int main(void) { + // "hello world\n": string + // printf: print + f (format) + printf("Hello World\n"); + + // return statement (return to operating system) + // 0: exit code + return 0; +} \ No newline at end of file