laba6
This commit is contained in:
7
lab-6/.github/copilot-instructions.md
vendored
Normal file
7
lab-6/.github/copilot-instructions.md
vendored
Normal file
@@ -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`.
|
||||
2
lab-6/.gitignore
vendored
Normal file
2
lab-6/.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
/build/
|
||||
/cmake-build-*/
|
||||
13
lab-6/CMakeLists.txt
Normal file
13
lab-6/CMakeLists.txt
Normal file
@@ -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)
|
||||
|
||||
30
lab-6/README.md
Normal file
30
lab-6/README.md
Normal file
@@ -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.
|
||||
31
lab-6/src/main.c
Normal file
31
lab-6/src/main.c
Normal file
@@ -0,0 +1,31 @@
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
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;
|
||||
}
|
||||
10
lab-6/tests/test_greeting.c
Normal file
10
lab-6/tests/test_greeting.c
Normal file
@@ -0,0 +1,10 @@
|
||||
#include <assert.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "greeting.h"
|
||||
|
||||
int main(void)
|
||||
{
|
||||
assert(strcmp(greeting_message(), "Hello, world!") == 0);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user