diff --git a/CMakeLists.txt b/CMakeLists.txt index 6ea464c..ffd031b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,8 +1,26 @@ cmake_minimum_required(VERSION 3.25) -project(sorting_station C) +project(C_homework C) +add_compile_options(-Wall -Wextra -pedantic) +# Libraries add_library(stack src/stack_and_queue/stack/stack.c) +# Executables and links with libraries +add_executable(hello_world src/hello_world/hello_world.c) + +add_executable(fast_calc_of_polynom src/homework_deadline_25_sep/fast_calculation_of_polynomial/fast_calculation_of_polynomial.c) + +add_executable(incomplete_quotient src/homework_deadline_25_sep/incomplete_quotient/incomplete_quotient.c) + +add_executable(lucky_tickets src/homework_deadline_25_sep/lucky_tickets/lucky_tickets.c) + +add_executable(massive_reroll src/homework_deadline_25_sep/massive_reroll/massive_reroll.c) + add_executable(sorting_station src/stack_and_queue/stack/sorting_station.c) target_link_libraries(sorting_station PRIVATE stack) -target_compile_options(sorting_station PRIVATE -Wall -Wextra -pedantic) + +add_executable(number_of_zero_elements src/compilation_process/number_of_zero_elements/number_of_zero_elements.c) + +add_executable(simple_bracket_balance src/compilation_process/simple_bracket_balance/simple_bracket_balance.c) + +add_executable(search_for_a_substring src/compilation_process/search_for_a_substring/search_for_a_substring.c) diff --git a/src/compilation_process/search_for_a_substring/search_for_a_substring.c b/src/compilation_process/search_for_a_substring/search_for_a_substring.c new file mode 100644 index 0000000..7deed9c --- /dev/null +++ b/src/compilation_process/search_for_a_substring/search_for_a_substring.c @@ -0,0 +1,35 @@ +#include +#include + +int main() +{ + char* string = NULL; + char* substring = NULL; + size_t stringSize = 0; + size_t substringSize = 0; + + printf("Enter string: "); + int realStringSize = getline(&string, &stringSize, stdin); + printf("Enter substring: "); + int realSubstringSize = getline(&substring, &substringSize, stdin); + + int substringCount = 0; + for (int i = 0; i < realStringSize - 1; i++) { + if (string[i] == substring[0]) { + substringCount++; + for (int j = 0; j < realSubstringSize - 1; j++) { + if (string[i + j] != substring[j]) { + substringCount--; + break; + } + } + } + } + + printf("Substring count in string: %d \n", substringCount); + + free(string); + free(substring); + + return 0; +} diff --git a/src/hello_world/hello_world.c b/src/hello_world/hello_world.c new file mode 100644 index 0000000..88682ec --- /dev/null +++ b/src/hello_world/hello_world.c @@ -0,0 +1,8 @@ +#include + +int main() +{ + printf("Hello, World!\n"); + + return 0; +}