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);