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

View File

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