diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..439e6d4 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,6 @@ +{ + "files.associations": { + "head.h": "c", + "unistd.h": "c" + } +} diff --git a/PROJECT/func.c b/PROJECT/func.c index afee160..68fa35d 100644 --- a/PROJECT/func.c +++ b/PROJECT/func.c @@ -1,8 +1,7 @@ #include -#include #include #include -#include +#include double f(double x) { @@ -19,20 +18,19 @@ void find_zero(double *pa, double *pb, double eps, double *px) printf("Текущее приближение: %lf\n", *px); } -void ctrlc_handler(int signum) +void ctrlc_handler(int signum, char *ch) { - int sig; - sigset_t *set = (sigset_t *)signum; - - while (1) - { - sigwait(set, &sig); - if (sig == SIGINT) - { - printf("\nПолучен сигнал Ctrl+C\n"); - printf("Продолжить поиск корня? (C - продолжить, A - закончить работу программы, R - начать поиск на другом отрезке): "); - } - } + printf("\nПолучен сигнал Ctrl+C\n"); + printf("\nПродолжить поиск корня? (C - продолжить, A - закончить работу программы, R - начать поиск на другом отрезке): \n"); } -// void choose_path(char *choice); + +// void choose_path() +// { +// char choice = getchar(); +// if(choice == 'A') +// break; +// else if(choice == 'C') +// find_zero() + +// } // void new_row(double *pa, double *pb); \ No newline at end of file diff --git a/PROJECT/main.c b/PROJECT/main.c index e1ac274..fd93e1f 100644 --- a/PROJECT/main.c +++ b/PROJECT/main.c @@ -1,53 +1,41 @@ #include #include #include -#include +#include -double f(double x); // function x -void find_zero(double *pa, double *pb, double eps, double *px); // -void ctrlc_handler(int signum); -// void choose_path(char *choice); -// void new_row(double *pa, double *pb); +double f(double x); +void find_zero(double *pa, double *pb, double eps, double *px); +void ctrlc_handler(int signum, char *ch); +void choose_path(); +void new_row(double *pa, double *pb); int main() { double a, b, eps, x, *pa = &a, *pb = &b, *px = &x; - char choice = ' ', *ch = &choice; - pthread_t thread; - sigset_t set; + char choice, *ch = &choice; + struct sigaction sa; + sa.sa_handler = ctrlc_handler(, ch); + sa.sa_flags = 0; + sigemptyset(&sa.sa_mask); printf("Введите интервал [a, b] и точность eps: "); scanf("%lf %lf %lf", pa, pb, &eps); + find_zero(pa, pb, eps, px); - // Создание набора сигналов и добавление в него SIGINT - sigemptyset(&set); - sigaddset(&set, SIGINT); - - // Блокировка сигналов в наборе для основного потока - if (pthread_sigmask(SIG_BLOCK, &set, NULL) != 0) + if (sigaction(SIGINT, &sa, NULL) == -1) { - perror("pthread_sigmask"); - return 1; - } - - // Создание потока для обработчика сигнала - if (pthread_create(&thread, NULL, ctrlc_handler, &set) != 0) - { - perror("pthread_create"); + perror("sigaction"); return 1; } printf("Ожидание сигнала Ctrl+C...\n"); - find_zero(pa, pb, eps, px); while (1) { sleep(1); } - signal(SIGINT, ctrlc_handler); - - printf("Корень уравнения: %lf\n", *px); + printf("\nКорень уравнения: %lf\n", *px); printf("Работа программы завершена.\n"); return 0; diff --git a/PROJECT/out_p/prog3 b/PROJECT/out_p/prog3 deleted file mode 100755 index 0dc01f3..0000000 Binary files a/PROJECT/out_p/prog3 and /dev/null differ diff --git a/PROJECT/out_p/prog4 b/PROJECT/out_p/prog4 new file mode 100755 index 0000000..fb1721b Binary files /dev/null and b/PROJECT/out_p/prog4 differ diff --git a/PROJECT/try/out/app1 b/try/out/app1 similarity index 100% rename from PROJECT/try/out/app1 rename to try/out/app1 diff --git a/PROJECT/try/test.c b/try/test.c similarity index 100% rename from PROJECT/try/test.c rename to try/test.c diff --git a/PROJECT/try/var1.c b/try/var1.c similarity index 100% rename from PROJECT/try/var1.c rename to try/var1.c diff --git a/PROJECT/try/var2.c b/try/var2.c similarity index 100% rename from PROJECT/try/var2.c rename to try/var2.c