From f4d0acead99620b4e038c6a24c47962cbceecc81 Mon Sep 17 00:00:00 2001 From: Miloslav Macko Date: Fri, 22 Mar 2024 12:59:25 +0100 Subject: [PATCH] 22.3 --- a1/program.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/a1/program.c b/a1/program.c index 01c48c6..0285ef8 100644 --- a/a1/program.c +++ b/a1/program.c @@ -10,11 +10,6 @@ bool is_operator(char c) { return c == '+' || c == '-' || c == '*' || c == '/'; } -// Funkcia na kontrolu, či je daný znak medzera -bool is_space(char c) { - return c == ' '; -} - // Funkcia na kontrolu, či je daný znak číslica bool is_digit(char c) { return isdigit(c); @@ -49,10 +44,10 @@ int main() { char op; double num1, num2, result; - int scanned = sscanf(line, "%lf%*[ ]%c%*[ ]%lf%*[ ]=%*[ ]%lf", &num1, &op, &num2, &result); + int scanned = sscanf(line, "%lf%*[^0-9-]%c%*[^0-9-]%lf=%lf", &num1, &op, &num2, &result); // Kontrola, či boli načítané správne hodnoty - if (scanned != 4 || !is_operator(op) || !is_digit(line[0]) || !is_digit(line[len-2]) || line[len-3] != ' ') + if (scanned != 4 || !is_operator(op)) printf("CHYBA\n"); else { double calculated_result = calculate(num1, op, num2);