This commit is contained in:
Sadchenko 2024-03-27 13:04:36 +01:00
parent 56532263e3
commit e8dc682eeb

View File

@ -5,15 +5,10 @@
#include <math.h> #include <math.h>
char* check_math_problem(const char* problem) { char* check_math_problem(const char* problem)
char* result_str = (char*)malloc(10 * sizeof(char)); {
if (result_str == NULL) {
fprintf(stderr, "Error with memory\n");
exit(EXIT_FAILURE);
}
//char* copy;
//char* copy = strcmp(problem);
char* copy = (char*)malloc((strlen(problem) + 1) * sizeof(char)); char* copy = (char*)malloc((strlen(problem) + 1) * sizeof(char));
strcpy(copy, problem); strcpy(copy, problem);
if (copy == NULL) { if (copy == NULL) {
@ -74,16 +69,16 @@ char* check_math_problem(const char* problem) {
free(copy); free(copy);
return "CHYBA"; return "CHYBA";
} }
free(copy);
if (fabs(result - res) < 0.01) { if (fabs(result - res) < 0.01) {
strcpy(result_str, "OK"); return "OK";
} else { } else {
strcpy(result_str, "ZLE"); return "ZLE";
} }
free(copy); return "0";
return result_str;
} }
int main() { int main() {