Compare commits

..

No commits in common. "f4d0acead99620b4e038c6a24c47962cbceecc81" and "cdcb8a0bd4ce112bac41519ec757d4c10c6ea515" have entirely different histories.

View File

@ -10,6 +10,11 @@ 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);
@ -44,10 +49,10 @@ int main() {
char op;
double num1, num2, result;
int scanned = sscanf(line, "%lf%*[^0-9-]%c%*[^0-9-]%lf=%lf", &num1, &op, &num2, &result);
int scanned = sscanf(line, "%lf %c %lf = %lf", &num1, &op, &num2, &result);
// Kontrola, či boli načítané správne hodnoty
if (scanned != 4 || !is_operator(op))
if (scanned != 4 || !is_operator(op) || !is_digit(line[0]) || !is_digit(line[len-2]) || line[len-3] != ' ')
printf("CHYBA\n");
else {
double calculated_result = calculate(num1, op, num2);