From c614a32f8ce2f59f1f395fb3701d9c7b867f79f5 Mon Sep 17 00:00:00 2001 From: Weber Date: Mon, 14 Oct 2024 13:23:54 +0000 Subject: [PATCH] test --- cv3/program.c | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/cv3/program.c b/cv3/program.c index 6b24072..6e60330 100644 --- a/cv3/program.c +++ b/cv3/program.c @@ -72,6 +72,10 @@ void zobraz_zasobnik(KalkulackaZasobnik *kalkulacka) { printf("\n"); } +bool je_platna_operacia(char operacia) { + return operacia == '+' || operacia == '-' || operacia == '*' || operacia == '/'; +} + int main() { KalkulackaZasobnik kalkulacka; inicializuj(&kalkulacka); @@ -92,6 +96,10 @@ int main() { zobraz_zasobnik(&kalkulacka); } if (sscanf(vstup + snprintf(NULL, 0, "%.2f", hodnota), " %c", &operacia) == 1) { + if (!je_platna_operacia(operacia)) { + printf("bad input\n"); + return 0; + } switch (operacia) { case '+': if (scitat(&kalkulacka)) { @@ -127,15 +135,9 @@ int main() { vloz(&kalkulacka, b / a); zobraz_zasobnik(&kalkulacka); } - } else { - printf("no input\n"); - return 0; } break; } - default: - printf("no input\n"); - return 0; } } } else {