22.3
This commit is contained in:
parent
76343f40d7
commit
f4d0acead9
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user