diff --git a/a1/program.c b/a1/program.c index 1cb7384..28d47d3 100644 --- a/a1/program.c +++ b/a1/program.c @@ -4,7 +4,49 @@ #include #include +bool check_spaces(const char* str) { + int len = strlen(str); + bool is_operator = false; + bool is_operand = false; + + for (int i = 0; i < len; ++i) { + char current_char = str[i]; + + + if (current_char == ' ') { + if (!is_operator && !is_operand) { + return false; + } + } + + else if (current_char >= '0' && current_char <= '9') { + is_operand = true; + is_operator = false; + } + + else if (current_char == '+' || current_char == '-' || current_char == '*' || current_char == '/') { + is_operator = true; + is_operand = false; + } + + else { + return false; + } + } + + + if (!is_operand) { + return false; + } + + return true; +} + char* check_math_problem(const char* problem) { + if (!check_spaces(problem)) { + return "ZLE"; + } + if (strlen(problem) == 0) { return "CHYBA"; } @@ -16,6 +58,10 @@ char* check_math_problem(const char* problem) { return "CHYBA"; } + if (equel != '=') { + return "CHYBA"; + } + double result; switch (sing) { case '+': @@ -57,3 +103,8 @@ int main() { return 0; } + + + + +