Sadchenko 2 months ago
parent
commit
6c2fc4d6d8
  1. 18
      a1/program.c

18
a1/program.c

@ -7,6 +7,7 @@
bool check_spaces(const char* str) {
int len = strlen(str);
bool result_found = false;
for (int i = 0; i < len - 1; ++i) {
if (str[i] == '+' || str[i] == '-' || str[i] == '*' || str[i] == '/') {
@ -17,17 +18,16 @@ bool check_spaces(const char* str) {
if (str[i + 1] != ' ')
return false;
}
if (isdigit(str[i]) && isspace(str[i + 1])) {
result_found = true;
}
}
if (str[len - 2] == '+' || str[len - 2] == '-' || str[len - 2] == '*' || str[len - 2] == '/')
return false;
if (isdigit(str[len - 2]) && str[len - 1] == ' ')
return false;
return true;
return result_found;
}
char* check_math_problem(const char* problem) {
@ -50,11 +50,6 @@ char* check_math_problem(const char* problem) {
return "CHYBA";
}
// Проверяем, что после результата нет пробела
if (strchr(problem, '=') - strchr(problem, ' ') == 2) {
return "CHYBA";
}
double result;
switch (sing) {
case '+':
@ -99,3 +94,6 @@ int main() {

Loading…
Cancel
Save