From e8dc682eeb4ebf86d9b943ca318413e2302cce30 Mon Sep 17 00:00:00 2001 From: Mykyta Sadchenko Date: Wed, 27 Mar 2024 13:04:36 +0100 Subject: [PATCH] funguje --- a1/program.c | 23 +++++++++-------------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/a1/program.c b/a1/program.c index 9ac68c5..c5c54e1 100644 --- a/a1/program.c +++ b/a1/program.c @@ -5,17 +5,12 @@ #include -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() {