diff options
author | justanothercatgirl <sotov2070@gmail.com> | 2024-10-07 21:16:59 +0300 |
---|---|---|
committer | justanothercatgirl <sotov2070@gmail.com> | 2024-10-07 21:16:59 +0300 |
commit | 1fe251abc83ee3a38d9faea5be947c90d162c6ae (patch) | |
tree | fd9e71bfbc1c66a55a601dc8cb001d71d3b7d447 /src | |
parent | d4b67741a8edb86128e1f29071703785511b76e4 (diff) |
fixed buffering input issuestask4
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 14 |
1 files changed, 11 insertions, 3 deletions
@@ -1,8 +1,10 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <ctype.h> #include <unistd.h> +#include <termios.h> #include <sys/fcntl.h> #include <sys/stat.h> #include <sys/types.h> @@ -104,6 +106,12 @@ exit: return ret; } +char _getchar(void) { + char ret; + while (isspace(ret = getchar())); + return ret; +} + // Prompts user to choose input method enum optype get_optype(void) { prompt_init: @@ -113,7 +121,7 @@ prompt_init: "\t3: численно вычислить интеграл f(x)\n" "Введите число: ", stdout); char c; - switch (getchar()-'0') { + switch (_getchar()-'0') { case 1: return SOL_ITERN; case 2: @@ -123,7 +131,7 @@ prompt_init: "\t2: хорд\n" "\t3: касательных (Ньютона)\n" "Введите число:", stdout); - c = getchar() - '0'; + c = _getchar() - '0'; if (c <= 0 || c > 3) goto prompt_sol; return SOL_BINSR + c - 1; @@ -134,7 +142,7 @@ prompt_init: "\t2: трапеций\n" "\t3: Симпсона (парабол)\n" "Введите число: ", stdout); - c = getchar() - '0'; + c = _getchar() - '0'; if (c <= 0 || c > 3) goto prompt_int; return INT_RECT + c - 1; |