commit 4385c667aac20b8ee5a9a5825ada3805b4cfc1be Author: FIFIFiSKA Date: Tue Oct 20 08:58:53 2026 +0300 laba6 diff --git a/lab-6/.github/copilot-instructions.md b/lab-6/.github/copilot-instructions.md new file mode 100644 index 0000000..c352196 --- /dev/null +++ b/lab-6/.github/copilot-instructions.md @@ -0,0 +1,7 @@ +# Workspace Instructions + +- Keep the project compatible with C11 and CMake 3.16 or newer. +- Put public headers in `include/`, implementations in `src/`, and tests in `tests/`. +- Keep reusable functionality in libraries and link executables to those libraries. +- Register tests with CTest and avoid adding dependencies unless the project needs them. +- Verify changes with `cmake -S . -B build`, `cmake --build build`, and `ctest --test-dir build --output-on-failure`. \ No newline at end of file diff --git a/lab-6/.gitignore b/lab-6/.gitignore new file mode 100644 index 0000000..a52d603 --- /dev/null +++ b/lab-6/.gitignore @@ -0,0 +1,2 @@ +/build/ +/cmake-build-*/ \ No newline at end of file diff --git a/lab-6/CMakeLists.txt b/lab-6/CMakeLists.txt new file mode 100644 index 0000000..48ec035 --- /dev/null +++ b/lab-6/CMakeLists.txt @@ -0,0 +1,13 @@ +cmake_minimum_required(VERSION 3.16) + +project(c_template VERSION 1.0.0 LANGUAGES C) + +include(CTest) + +# add_library(greeting src/greeting.c) +# target_include_directories(greeting PUBLIC include) +# target_compile_features(greeting PUBLIC c_std_11) + +add_executable(c_template src/main.c) +# target_link_libraries(c_template PRIVATE greeting) + diff --git a/lab-6/README.md b/lab-6/README.md new file mode 100644 index 0000000..226ca62 --- /dev/null +++ b/lab-6/README.md @@ -0,0 +1,30 @@ +# CMake C Template + +A small C11 project template with a reusable library, executable, and CTest test. + +## Requirements + +- CMake 3.16 or newer +- A C compiler with C11 support + +## Configure and build + +```sh +cmake -S . -B build +cmake --build build +``` + +## Run + +```sh +./build/c_template +``` + +## Test + +```sh +ctest --test-dir build --output-on-failure +``` + +The `greeting` library is an example of how to separate reusable code into a +public header and implementation. Replace it with your project's own modules. \ No newline at end of file diff --git a/lab-6/src/main.c b/lab-6/src/main.c new file mode 100644 index 0000000..1437955 --- /dev/null +++ b/lab-6/src/main.c @@ -0,0 +1,31 @@ +#include +#include + +int main(void){ + char str[100]; + printf("Введите строку: "); + fgets(str, sizeof(str), stdin); + str[strcspn(str, "\n")] = '\0'; + + int i = 0; + int size = strlen(str); + + + while (str[i] != '\0') { + if (i != 0) { + if ( (str[i-1] == ' ') && (str[i] == ' ')){ + for (int j = i; j < size; j++) { + str[j] = str[j + 1]; + } + size--; + } else{ + i++; + } + }else{ + i++; + } + } + + printf("Результат: \"%s\"\n", str); + return 0; +} \ No newline at end of file diff --git a/lab-6/tests/test_greeting.c b/lab-6/tests/test_greeting.c new file mode 100644 index 0000000..1627ea7 --- /dev/null +++ b/lab-6/tests/test_greeting.c @@ -0,0 +1,10 @@ +#include +#include + +#include "greeting.h" + +int main(void) +{ + assert(strcmp(greeting_message(), "Hello, world!") == 0); + return 0; +} \ No newline at end of file